1 from django import template
2 from django.template.defaultfilters import stringfilter
6 register = template.Library()
8 DEFAULTS = dict(size=80, rating='g', default='monsterid')
10 class GravatarNode(template.Node):
12 def __init__(self, email, size):
13 self.email = template.Variable(email)
16 def render(self, context):
18 email = self.email.resolve(context)
19 except template.VariableDoesNotExist:
22 gravatar_url = "http://www.gravatar.com/avatar/" + hashlib.md5(email).hexdigest() + "?"
23 gravatar_url += urllib.urlencode({'default': 'wavatar', 'size': str(self.size)})
28 def gravatar(parser, token):
30 _tag_name, email, size = token.split_contents()
32 raise template.TemplateSyntaxError, "%r tag requires two args" % token.contents.split()[0]
34 return GravatarNode(email, int(size))
39 @register.filter(name='md5')