forked from ntucker/django-user-accounts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move receiver for user creation signal to own module
- Loading branch information
Showing
2 changed files
with
21 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from django.dispatch import receiver | ||
from django.db.models.signals import post_save | ||
from django.contrib.auth.models import User | ||
|
||
from .models import Account | ||
|
||
@receiver(post_save, sender=User) | ||
def user_post_save(sender, **kwargs): | ||
""" | ||
After User.save is called we check to see if it was a created user. If so, | ||
we check if the User object wants account creation. If all passes we | ||
create an Account object. | ||
We only run on user creation to avoid having to check for existence on | ||
each call to User.save. | ||
""" | ||
user, created = kwargs["instance"], kwargs["created"] | ||
disabled = getattr(user, "_disable_account_creation", not settings.ACCOUNT_CREATE_ON_SAVE) | ||
if created and not disabled: | ||
Account.create(user=user) |