Commit 771bbbde45118ede139c04aa5d54138c72712f9f

Authored by Sergio Oliveira
1 parent 55a5ebc1

Fixed gravatar protocol

Showing 1 changed file with 11 additions and 3 deletions   Show diff stats
colab/accounts/templatetags/gravatar.py
... ... @@ -7,8 +7,8 @@ from colab.super_archives.models import EmailAddress
7 7 register = template.Library()
8 8  
9 9  
10   -@register.simple_tag
11   -def gravatar(email, size=80):
  10 +@register.simple_tag(takes_context=True)
  11 +def gravatar(context, email, size=80):
12 12 if isinstance(email, basestring):
13 13 try:
14 14 email = EmailAddress.objects.get(address=email)
... ... @@ -17,4 +17,12 @@ def gravatar(email, size=80):
17 17  
18 18 email_md5 = getattr(email, 'md5', 'anonymous')
19 19  
20   - return u'<img src="www.gravatar.com/avatar/{}?s={}&d=mm" height="{}px" width="{}px" />'.format(email_md5, size, size, size)
  20 + request = context.get('request')
  21 + if getattr(request, 'is_secure'):
  22 + protocol = 'https'
  23 + else:
  24 + protocol = 'http'
  25 +
  26 + return (u'<img src="{}://www.gravatar.com/avatar/{}?s={}&d=mm"'
  27 + 'height="{}px" width="{}px" />').format(protocol, email_md5,
  28 + size, size, size)
... ...