I am using python-social-auth API for authentication for facebook in my website. But I am getting an exception.
while using 'apps.pipeline.save_profile'
'cannot import name save_status_to_session'
I am using django-pipeline version 1.6.13
This code in pipelne.py
def require_email(strategy, details, user=None, is_new=False, *args, **kwargs):
if kwargs.get('ajax') or user and user.email:
return
elif is_new and not details.get('email'):
email = strategy.request_data().get('email')
if email:
details['email'] = email
elif email is None:
error = "Sorry, but your social network (Facebook or Google)
needs to provide us your email address."
return HttpResponseRedirect(reverse('django.contrib.auth.views.login') + "?error=" + urllib.quote_plus(error))
else:
return redirect('require_email')
def save_profile(backend, details, response, uid,user, *args, **kwargs):
if backend.name == 'facebook':
url = "http://graph.facebook.com/%s/picture?type=large" % response['id']
avatar = urlopen(url)
profile = Profile.objects.filter(user_id=user.id)
if profile.count()==0:
profile = Profile(user_id=user.id)
else:
profile = Profile.objects.get(user_id=user.id)
profile.profile_image.save(slugify(user.username + " social") + '.jpg',
ContentFile(avatar.read()))
profile.save()
elif backend.name == 'google-oauth2':
if response.get('image') and response['image'].get('url'):
url = response['image'].get('url')
ext = url.split('.')[-1]
profile = Profile.objects.filter(user_id=user.id)
if profile.count()==0:
profile = Profile(user_id=user.id)
else:
profile = Profile.objects.get(user_id=user.id)
profile.profile_image.save(
'{0}.{1}'.format(user.username, ext),
ContentFile(urllib2.urlopen(url).read()),
save=False
)
profile.save()
And settings
SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.social_auth.associate_by_email',
'social.pipeline.user.get_username',
'polls.pipeline.require_email',
'social.pipeline.user.create_user',
'polls.pipeline.save_profile',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
)