Permalink
Browse files

merged with Raymond's updates

  • Loading branch information...
2 parents 847319b + 68426d7 commit e936be58dd2a8a8693b1ca4a2b239ec1bddc68c8 autalpha committed Feb 14, 2011
View
@@ -3,3 +3,6 @@
.idea
.project
.pydevproject
+build
+dist
+django_allauth.egg-info
View
@@ -1,3 +1,8 @@
+2011-02-13 Raymond Penners <raymond.penners@intenct.nl>
+
+ * Added support for django-avatar, copying the Twitter profile
+ image locally on signup.
+
2010-11-12 Raymond Penners <raymond.penners@intenct.nl>
* allauth/account/forms.py (BaseSignupForm.clean_email): With
View
@@ -12,7 +12,7 @@ Installation
Django
------
-settings.py:
+settings.py::
TEMPLATE_CONTEXT_PROCESSORS = (
...
@@ -36,7 +36,7 @@ settings.py:
'allauth.openid',
'allauth.facebook',
-urls.py:
+urls.py::
urlpatterns = patterns('',
...
@@ -71,6 +71,13 @@ SOCIALACCOUNT_AUTO_SIGNUP (=True)
arises due to a duplicate e-mail address the signup form will still
kick in.
+SOCIALACCOUNT_AVATAR_SUPPORT (= 'avatar' in settings.INSTALLED_APPS)
+ Enable support for django-avatar. When enabled, the profile image of
+ the user is copied locally into django-avatar at signup.
+
+EMAIL_CONFIRMATION_DAYS (=# of days, no default)
+ Determines the expiration date of email confirmation mails sent by
+ django-email-confirmation.
Facebook & Twitter
------------------
@@ -11,3 +11,7 @@
# arises due to a duplicate e-mail signup form will still kick in.
AUTO_SIGNUP = getattr(settings, "SOCIALACCOUNT_AUTO_SIGNUP", True)
+# Enable support for django-avatar. When enabled, the profile image of
+# the user is copied locally into django-avatar at signup.
+AVATAR_SUPPORT = getattr(settings, "SOCIALACCOUNT_AVATAR_SUPPORT",
+ 'avatar' in settings.INSTALLED_APPS)
@@ -60,7 +60,7 @@ def _process_signup(request, data, account):
account.user = u
account.save()
send_email_confirmation(u, request=request)
- ret = complete_signup(request, u, get_login_redirect_url(request))
+ ret = complete_social_signup(request, u, account)
return ret
@@ -116,4 +116,26 @@ def complete_social_login(request, data, account):
return ret
+def _copy_avatar(request, user, account):
+ import urllib2
+ from django.core.files.base import ContentFile
+ from urlparse import urlparse
+ from avatar.models import Avatar
+ url = account.get_avatar_url()
+ if url:
+ ava = Avatar(user=user)
+ ava.primary = Avatar.objects.filter(user=user).count() == 0
+ try:
+ name = urlparse(url).path
+ content = urllib2.urlopen(url).read()
+ ava.avatar.save(name, ContentFile(content))
+ except IOError, e:
+ # Let's nog make a big deal out of this...
+ pass
+
+def complete_social_signup(request, user, account):
+ success_url = get_login_redirect_url(request)
+ if app_settings.AVATAR_SUPPORT:
+ _copy_avatar(request, user, account)
+ return complete_signup(request, user, success_url)
@@ -19,6 +19,8 @@ def authenticate(self):
def __unicode__(self):
return unicode(self.user)
+ def get_avatar_url(self):
+ return None
def get_provider(self):
raise NotImplementedError
@@ -11,7 +11,6 @@
from allauth.utils import get_login_redirect_url
from allauth.account.views import signup as account_signup
-from allauth.account.utils import complete_signup
from models import SocialAccount
from forms import DisconnectForm, SignupForm
@@ -38,8 +37,7 @@ def signup(request, **kwargs):
account = signup['account']
account.user = user
account.save()
- return complete_signup(request, user,
- get_login_redirect_url(request))
+ return helpers.complete_social_signup(request, user, account)
else:
form = form_class(initial=data)
dictionary = dict(site=Site.objects.get_current(),
@@ -32,6 +32,13 @@ class TwitterAccount(SocialAccount):
def get_profile_url(self):
return 'http://twitter.com/' + self.username
+ def get_avatar_url(self):
+ ret = None
+ if self.profile_image_url:
+ # Hmm, hack to get our hands on the large image. Not
+ # really documented, but seems to work.
+ ret = self.profile_image_url.replace('_normal', '')
+ return ret
def get_provider(self):
return SocialAccountProvider.TWITTER
View
@@ -3,7 +3,7 @@
METADATA = dict(
name='django-allauth',
- version='0.0.1',
+ version='0.1.0',
author='Raymond Penners',
author_email='raymond.penners@intenct.nl',
description='Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication.',

0 comments on commit e936be5

Please sign in to comment.