From e862052dad33a5a408fe84333585bac99cf0f318 Mon Sep 17 00:00:00 2001 From: Juan Funez Date: Mon, 23 Feb 2015 11:11:28 -0300 Subject: [PATCH] Fix/Improve template tag: user_avatar --- .../templatetags/user_avatar.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scielomanager/journalmanager/templatetags/user_avatar.py b/scielomanager/journalmanager/templatetags/user_avatar.py index a6295736..70868996 100644 --- a/scielomanager/journalmanager/templatetags/user_avatar.py +++ b/scielomanager/journalmanager/templatetags/user_avatar.py @@ -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)