diff pylons_app/lib/helpers.py @ 398:8c50b164fb58

Implemented basic gravatar support on admin pages only for now
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 08 Aug 2010 01:26:23 +0200
parents 504feff57b49
children 7eba3d1e4227
line wrap: on
line diff
--- a/pylons_app/lib/helpers.py	Sat Aug 07 22:08:31 2010 +0200
+++ b/pylons_app/lib/helpers.py	Sun Aug 08 01:26:23 2010 +0200
@@ -277,8 +277,6 @@
 #===============================================================================
 # MERCURIAL FILTERS available via h.
 #===============================================================================
-
-
 from mercurial import util
 from mercurial.templatefilters import age as _age, person as _person
 
@@ -302,4 +300,24 @@
 from pylons_app.lib.auth import HasPermissionAny, HasPermissionAll, \
 HasRepoPermissionAny, HasRepoPermissionAll
 
+#===============================================================================
+# GRAVATAR URL
+#===============================================================================
+import hashlib
+import urllib
 
+def gravatar_url(email):
+    ssl_enabled = 'https' == request.environ.get('HTTP_X_URL_SCHEME')
+    default = 'identicon'
+    size = 32
+    baseurl_nossl = "http://www.gravatar.com/avatar/"
+    baseurl_ssl = "https://secure.gravatar.com/avatar/"
+    
+    baseurl = baseurl_ssl if ssl_enabled else baseurl_nossl
+        
+    
+    # construct the url
+    gravatar_url = baseurl + hashlib.md5(email.lower()).hexdigest() + "?"
+    gravatar_url += urllib.urlencode({'d':default, 's':str(size)})
+
+    return gravatar_url