views:

297

answers:

4

I am writing a Django app, and I would like an account to be created on our Google Apps hosted email using the Provisioning API whenever an account is created locally.

I would solely use signals, but since I would like the passwords to be synchronized across sites, I have monkeypatched User.objects.create_user and User.set_password using wrappers to create Google accounts and update passwords respectively.

Monkeypatching seems to be frowned upon, so I would to know, is there a better way to accomplish this?

+1  A: 

Have you considered subclassing the User model? This may create a different set of problems, and is only available with newer releases (not sure when the change went in, I'm on trunk).

bstpierre
A: 

Subclassing seems the best route, as long as you can change all of your code to use the new class. I think that's supported in the latest release of Django.

lfaraone
A: 

Monkeypatching is definitely bad. Hard to say anything since you've given so little code/information. But I assume you have the password in cleartext at some point (in a view, in a form) so why not sync manually then?

muhuk
A: 

I subclass User with Django 1.0.2. You basically makes another table that links to the user_id.

class User(MyBaseModel):
    user = models.OneToOneField(User, help_text="The django created User object")

and then at runtime

@login_required
def add(request) :
    u = request.user.get_profile()

You can then easily overwrite the needed methods.

And for those that hadn't heard of monkeypatching : http://en.wikipedia.org/wiki/Monkey_patch. It is a derivation from guerrilla patch.

Paul Tarjan