2011-09-12 05:53:54 +00:00
|
|
|
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
|
|
|
|
|
2011-09-06 03:50:38 +00:00
|
|
|
from social_auth.signals import pre_update
|
|
|
|
from social_auth.backends.facebook import FacebookBackend
|
2011-09-16 02:53:44 +00:00
|
|
|
from tastypie.models import create_api_key
|
2011-09-06 03:50:38 +00:00
|
|
|
|
2011-09-12 05:53:54 +00:00
|
|
|
|
2011-09-06 03:50:38 +00:00
|
|
|
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)
|
2011-09-12 05:53:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
def create_wishlist(sender, created, instance, **kwargs):
|
|
|
|
# use get_model to avoid circular import problem with models
|
|
|
|
try:
|
|
|
|
Wishlist = get_model('core', 'Wishlist')
|
|
|
|
if created:
|
|
|
|
Wishlist.objects.create(user=instance)
|
2011-09-16 02:53:44 +00:00
|
|
|
|
2011-09-12 05:53:54 +00:00
|
|
|
except DatabaseError:
|
2011-09-16 02:53:44 +00:00
|
|
|
# this can happen when creating superuser during syncdb since the
|
|
|
|
# core_wishlist table doesn't exist yet
|
2011-09-12 05:53:54 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
post_save.connect(create_wishlist, sender=User)
|
2011-09-16 02:53:44 +00:00
|
|
|
post_save.connect(create_api_key, sender=User)
|