changeset 2734:d2f552429ef3 beta

use dict for replacing parts of avatar URL and add example to ini template
author domruf <dominikruf@gmail.com>
date Fri, 24 Aug 2012 10:37:17 +0200
parents d62f09590246
children 9d8f63ff9219
files rhodecode/config/deployment.ini_tmpl rhodecode/lib/helpers.py
diffstat 2 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/config/deployment.ini_tmpl	Tue Aug 14 15:21:50 2012 +0200
+++ b/rhodecode/config/deployment.ini_tmpl	Fri Aug 24 10:37:17 2012 +0200
@@ -63,6 +63,13 @@
 force_https = false
 commit_parse_limit = 50
 use_gravatar = true
+## alternative_gravatar_url allows you to use your own avatar server application
+## the following parts of the URL will be replaced
+## %(email)s        user email
+## %(md5email)s     md5 hash of the user email (like at gravatar.com)
+## %(size)s         size of the image that is expected from the server application
+#alternative_gravatar_url = http://myavatarserver.com/getbyemail/%(email)s/%(size)s
+#alternative_gravatar_url = http://myavatarserver.com/getbymd5/%(md5email)s?s=%(size)s
 container_auth_enabled = false
 proxypass_auth_enabled = false
 default_encoding = utf8
--- a/rhodecode/lib/helpers.py	Tue Aug 14 15:21:50 2012 +0200
+++ b/rhodecode/lib/helpers.py	Fri Aug 24 10:37:17 2012 +0200
@@ -692,10 +692,11 @@
 #==============================================================================
 
 def gravatar_url(email_address, size=30):
-    if(config['app_conf'].get('alternative_gravatar')):
-        if(str2bool(config['app_conf'].get('alternative_gravatar_hash'))):
-            email_address = hashlib.md5(email_address.lower()).hexdigest()
-        return "%s/%s?s=%s" % (config['app_conf'].get('alternative_gravatar').strip('/'), email_address, size)
+    if(str2bool(config['app_conf'].get('use_gravatar')) and
+       config['app_conf'].get('alternative_gravatar_url')):
+        return config['app_conf'].get('alternative_gravatar_url') % {'email': email_address,
+                                                                     'md5email': hashlib.md5(email_address.lower()).hexdigest(),
+                                                                     'size': size}
     if (not str2bool(config['app_conf'].get('use_gravatar')) or
         not email_address or email_address == 'anonymous@rhodecode.org'):
         f = lambda a, l: min(l, key=lambda x: abs(x - a))