diff options
-rw-r--r-- | app/blog/models.py | 11 | ||||
-rw-r--r-- | app/lib/templatetags/templatetags/gravatar_local.py | 9 | ||||
-rw-r--r-- | design/templates/comments/list.html | 2 |
3 files changed, 9 insertions, 13 deletions
diff --git a/app/blog/models.py b/app/blog/models.py index 1b828fe..afa7158 100644 --- a/app/blog/models.py +++ b/app/blog/models.py @@ -221,14 +221,3 @@ def cache_gravatar(sender, comment, **kwargs): os.makedirs(grav_dir) local_grav = '%s/%s.jpg' % (grav_dir, calculate_gravatar_hash(comment.email)) urllib.request.urlretrieve(url, local_grav) - else: - dest = '%s/%s.jpg' % (grav_dir, calculate_gravatar_hash(comment.email)) - src = settings.IMAGES_ROOT + '/gravcache/default.jpg' - try: - shutil.copy(src, dest) - # eg. src and dest are the same file - except shutil.Error as e: - print('Error: %s' % e) - # eg. source or destination doesn't exist - except IOError as e: - print('Error: %s' % e.strerror) diff --git a/app/lib/templatetags/templatetags/gravatar_local.py b/app/lib/templatetags/templatetags/gravatar_local.py index 985ed03..5ed9a7f 100644 --- a/app/lib/templatetags/templatetags/gravatar_local.py +++ b/app/lib/templatetags/templatetags/gravatar_local.py @@ -1,7 +1,7 @@ from django import template from django.utils.html import escape -from django_gravatar.helpers import calculate_gravatar_hash +from django_gravatar.helpers import calculate_gravatar_hash, has_gravatar # Get template.Library instance register = template.Library() @@ -17,4 +17,11 @@ def gravatar_hash(user_or_email): except: return '' +@register.filter +def has_grav(email): + if has_gravatar(email): + return True + else: + return False + register.simple_tag(gravatar_hash) diff --git a/design/templates/comments/list.html b/design/templates/comments/list.html index 569a60a..1fb1189 100644 --- a/design/templates/comments/list.html +++ b/design/templates/comments/list.html @@ -8,7 +8,7 @@ {% for comment in comment_list %} <div id="comment-{{ comment.id }}" class="comment"> <noscript class="datahashloader" data-hash="{%gravatar_hash comment.email %}"> - <img class="gravatar" src="https://images.luxagraf.net/gravcache/{%gravatar_hash comment.email %}.jpg" alt="gravatar icon for {{comment.name}}" /> + <img class="gravatar" {% if comment.email = "sng@luxagraf.net" %}src="https://images.luxagraf.net/gravcache/d64f4854965b2b1c3ecafee4b2a66fac.jpg" {%else%} {%if comment.email|has_grav %}src="https://images.luxagraf.net/gravcache/default.jpg"{%else%}src="https://images.luxagraf.net/gravcache/{%gravatar_hash comment.email %}.jpg{%endif%}{%endif%}" alt="gravatar icon for {{comment.name}}" /> </noscript> <div class="comment--head"> <span class="who"><b><a href="{{comment.url}}" rel="nofollow" target="_blank">{{comment.name}}</a></b></span> |