33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
from django.db.models import get_model
|
|
from django.db.utils import DatabaseError
|
|
from django.db.models.signals import post_save
|
|
from django.contrib.auth.models import User
|
|
|
|
from social_auth.signals import pre_update
|
|
from social_auth.backends.facebook import FacebookBackend
|
|
from tastypie.models import create_api_key
|
|
|
|
|
|
def facebook_extra_values(sender, user, response, details, **kwargs):
|
|
if response.get('email') is not None:
|
|
user.email = response.get('email')
|
|
return True
|
|
|
|
pre_update.connect(facebook_extra_values, sender=FacebookBackend)
|
|
|
|
def create_user_objects(sender, created, instance, **kwargs):
|
|
# use get_model to avoid circular import problem with models
|
|
try:
|
|
Wishlist = get_model('core', 'Wishlist')
|
|
UserProfile = get_model('core', 'UserProfile')
|
|
if created:
|
|
Wishlist.objects.create(user=instance)
|
|
UserProfile.objects.create(user=instance)
|
|
except DatabaseError:
|
|
# this can happen when creating superuser during syncdb since the
|
|
# core_wishlist table doesn't exist yet
|
|
return
|
|
|
|
post_save.connect(create_user_objects, sender=User)
|
|
post_save.connect(create_api_key, sender=User)
|