Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding support for gravatar fallback as well as hashed email addresses.

  • Loading branch information...
commit 2c2b3757ada68108dca1030e9770fa0122ad00da 1 parent 96684f9
@justinabrahms justinabrahms authored
Showing with 13 additions and 6 deletions.
  1. +13 −6 robotars/templatetags/robotars_tags.py
View
19 robotars/templatetags/robotars_tags.py
@@ -1,14 +1,21 @@
# http://robohash.org/
from django import template
-
+from md5 import md5
register = template.Library()
-
@register.inclusion_tag("robotars/robotar.html")
-def robotar(user, size=None):
- url = "http://robohash.org/%s" % user
+def robotar(user, size=None, gravatar_fallback=False, hashed=False):
+ _user = user
+ if hashed:
+ _user = md5(user).hexdigest()
+ url = "http://robohash.org/%s?" % _user
if size is not None:
- url += "?size=%s" % size
- return {"robotar_url": url, "robotar_user": user}
+ url += 'size=%s' % size
+ if gravatar_fallback:
+ sep = "?"
+ if "?size=" in url:
+ sep = "&"
+ url += "%sgravatar=%s" % (sep, "hashed" if hashed else "yes")
+ return {"robotar_url": url, "robotar_user": user}
Please sign in to comment.
Something went wrong with that request. Please try again.