Skip to content

Commit

Permalink
Fix/Improve template tag: user_avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
jfunez authored and Gustavo Fonseca committed Feb 23, 2015
1 parent c8649b7 commit e862052
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions scielomanager/journalmanager/templatetags/user_avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ def user_avatar_url(user, size):
size = int(size)
else:
return '' # unknow size, no photo

if not user or not user.is_authenticated() or not user.email:
return ''

try:
user_gravatar_email = user.email
except AttributeError: # possible user is None
user_profile = user.get_profile()
except UserProfile.DoesNotExist:
return ''
else:
if user_gravatar_email:
user_gravatar_id = user.get_profile().gravatar_id
params = urllib.urlencode({'s': size, 'd': 'mm'})
gravatar_url = getattr(settings, 'GRAVATAR_BASE_URL', 'https://secure.gravatar.com')
avartar_url = '{0}/avatar/{1}?{2}'.format(gravatar_url, user_gravatar_id, params)
return avartar_url
else:
return ''
params = urllib.urlencode({'s': size, 'd': 'mm'})
gravatar_url = getattr(settings, 'GRAVATAR_BASE_URL', 'https://secure.gravatar.com')
avartar_url = '{0}/avatar/{1}?{2}'.format(gravatar_url, user_profile.gravatar_id, params)
return avartar_url

register.simple_tag(user_avatar_url)

0 comments on commit e862052

Please sign in to comment.