bgneal@44: """ bgneal@44: Signal handler(s) for the bio application. bgneal@44: """ bgneal@44: from django.db.models.signals import post_save bgneal@44: from django.contrib.auth.models import User bgneal@44: from bio.models import UserProfile bgneal@44: bgneal@44: def on_user_save(sender, **kwargs): bgneal@44: """ bgneal@44: This signal handler ensures that every User has a corresonding bgneal@44: UserProfile. It is called after User instance is saved. It creates bgneal@44: a UserProfile for the User if the created argument is True. bgneal@44: """ bgneal@44: created = kwargs['created'] bgneal@44: if created: bgneal@44: user = kwargs['instance'] bgneal@44: profile = UserProfile() bgneal@44: profile.user = user bgneal@44: profile.save() bgneal@44: bgneal@44: bgneal@44: post_save.connect(on_user_save, sender=User)