Commit 5aab4ac206d313c68d37e9596442761646f76b24
1 parent
3f3e4760
Exists in
master
and in
39 other branches
Adding templatetag to insert gravatar avatar
Showing
3 changed files
with
22 additions
and
2 deletions
Show diff stats
| @@ -0,0 +1,20 @@ | @@ -0,0 +1,20 @@ | ||
| 1 | + | ||
| 2 | +from django import template | ||
| 3 | + | ||
| 4 | +from super_archives.models import EmailAddress | ||
| 5 | + | ||
| 6 | + | ||
| 7 | +register = template.Library() | ||
| 8 | + | ||
| 9 | + | ||
| 10 | +@register.simple_tag | ||
| 11 | +def gravatar(email, size=80): | ||
| 12 | + if isinstance(email, basestring): | ||
| 13 | + try: | ||
| 14 | + email = EmailAddress.objects.get(address=email) | ||
| 15 | + except EmailAddress.DoesNotExist: | ||
| 16 | + pass | ||
| 17 | + | ||
| 18 | + email_md5 = getattr(email, 'md5', 'anonymous') | ||
| 19 | + | ||
| 20 | + return u'<img src="http://www.gravatar.com/avatar/{}?s={}&d=mm" height="{}px" width="{}px">'.format(email_md5, size, size, size) |
src/super_archives/templates/message-thread.html
| 1 | {% extends "base.html" %} | 1 | {% extends "base.html" %} |
| 2 | {% load i18n %} | 2 | {% load i18n %} |
| 3 | {% load append_to_get %} | 3 | {% load append_to_get %} |
| 4 | +{% load gravatar %} | ||
| 4 | {% block main-content %} | 5 | {% block main-content %} |
| 5 | <div class="row"> | 6 | <div class="row"> |
| 6 | 7 | ||
| @@ -47,8 +48,7 @@ | @@ -47,8 +48,7 @@ | ||
| 47 | <li> | 48 | <li> |
| 48 | <div class="col-lg-2 text-center"> | 49 | <div class="col-lg-2 text-center"> |
| 49 | <a href="{{ email.from_address.get_profile_link }}"> | 50 | <a href="{{ email.from_address.get_profile_link }}"> |
| 50 | - <img width="80px" height="80px" | ||
| 51 | - src="http://www.gravatar.com/avatar/{{ email.from_address.md5 }}?s=80&d=identicon" /> | 51 | + {% gravatar email.from_address 80 %} |
| 52 | <div> </div> | 52 | <div> </div> |
| 53 | {% trans "Anonymous" as anonymous %} | 53 | {% trans "Anonymous" as anonymous %} |
| 54 | <span>{% firstof email.from_address.get_full_name anonymous %}</span> | 54 | <span>{% firstof email.from_address.get_full_name anonymous %}</span> |