Mercurial > public > sg101
comparison gpp/bio/signals.py @ 44:08cd19c1ee50
Added a signal handler for the user model to create a UserProfile for new users.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 17 Jun 2009 00:47:33 +0000 |
parents | |
children | b4305e18d3af |
comparison
equal
deleted
inserted
replaced
43:2763977301c2 | 44:08cd19c1ee50 |
---|---|
1 """ | |
2 Signal handler(s) for the bio application. | |
3 """ | |
4 from django.db.models.signals import post_save | |
5 from django.contrib.auth.models import User | |
6 from bio.models import UserProfile | |
7 | |
8 def on_user_save(sender, **kwargs): | |
9 """ | |
10 This signal handler ensures that every User has a corresonding | |
11 UserProfile. It is called after User instance is saved. It creates | |
12 a UserProfile for the User if the created argument is True. | |
13 """ | |
14 created = kwargs['created'] | |
15 if created: | |
16 user = kwargs['instance'] | |
17 profile = UserProfile() | |
18 profile.user = user | |
19 profile.save() | |
20 | |
21 | |
22 post_save.connect(on_user_save, sender=User) |