Factor out Gravatar hash calculation

(imported from commit 29872722fb4856773d98fc987a1e2d6eb99ad8b2)
This commit is contained in:
Keegan McAllister
2012-10-16 22:07:35 -04:00
parent e843427e6c
commit 81f0d61c3b
3 changed files with 9 additions and 3 deletions

5
zephyr/lib/avatar.py Normal file
View File

@@ -0,0 +1,5 @@
import hashlib
def gravatar_hash(email):
"""Compute the Gravatar hash for an email address."""
return hashlib.md5(email.lower()).hexdigest()

View File

@@ -10,6 +10,7 @@ import os
import simplejson
from django.db import transaction
from zephyr.lib import bugdown
from zephyr.lib.avatar import gravatar_hash
@cache_with_key(lambda self: 'display_recipient_dict:%d' % (self.id))
def get_display_recipient(recipient):
@@ -219,7 +220,7 @@ class Message(models.Model):
'subject' : self.subject,
'content' : content,
'timestamp' : calendar.timegm(self.pub_date.timetuple()),
'gravatar_hash' : hashlib.md5(self.sender.user.email.lower()).hexdigest(),
'gravatar_hash' : gravatar_hash(self.sender.user.email),
}
def to_log_dict(self):

View File

@@ -19,6 +19,7 @@ from django.views.decorators.csrf import csrf_exempt
from zephyr.decorator import asynchronous
from zephyr.lib.query import last_n
from zephyr.lib.avatar import gravatar_hash
from confirmation.models import Confirmation
@@ -26,7 +27,6 @@ import datetime
import simplejson
import socket
import re
import hashlib
import urllib
import time
@@ -186,7 +186,7 @@ def home(request):
return render_to_response('zephyr/index.html',
{'user_profile': user_profile,
'email_hash' : hashlib.md5(user_profile.user.email).hexdigest(),
'email_hash' : gravatar_hash(user_profile.user.email),
'people' : people,
'streams' : streams,
'have_initial_messages':