changeset 2751:e291f25ea87f beta

fixes issue #543, un-broken alternative gravatar option - also now formatting is similar as other parts `{}`
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 28 Aug 2012 09:05:27 +0200
parents 30cafecb2630
children 6d904a0cd48d
files development.ini production.ini rhodecode/config/deployment.ini_tmpl rhodecode/lib/helpers.py
diffstat 4 files changed, 21 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/development.ini	Tue Aug 28 09:04:02 2012 +0200
+++ b/development.ini	Tue Aug 28 09:05:27 2012 +0200
@@ -66,11 +66,11 @@
 
 ## 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
+## {email}        user email
+## {md5email}     md5 hash of the user email (like at gravatar.com)
+## {size}         size of the image that is expected from the server application
+#alternative_gravatar_url = http://myavatarserver.com/getbyemail/{email}/{size}
+#alternative_gravatar_url = http://myavatarserver.com/getbymd5/{md5email}?s={size}
 
 container_auth_enabled = false
 proxypass_auth_enabled = false
--- a/production.ini	Tue Aug 28 09:04:02 2012 +0200
+++ b/production.ini	Tue Aug 28 09:05:27 2012 +0200
@@ -66,11 +66,11 @@
 
 ## 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
+## {email}        user email
+## {md5email}     md5 hash of the user email (like at gravatar.com)
+## {size}         size of the image that is expected from the server application
+#alternative_gravatar_url = http://myavatarserver.com/getbyemail/{email}/{size}
+#alternative_gravatar_url = http://myavatarserver.com/getbymd5/{md5email}?s={size}
 
 container_auth_enabled = false
 proxypass_auth_enabled = false
--- a/rhodecode/config/deployment.ini_tmpl	Tue Aug 28 09:04:02 2012 +0200
+++ b/rhodecode/config/deployment.ini_tmpl	Tue Aug 28 09:05:27 2012 +0200
@@ -66,11 +66,11 @@
 
 ## 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
+## {email}        user email
+## {md5email}     md5 hash of the user email (like at gravatar.com)
+## {size}         size of the image that is expected from the server application
+#alternative_gravatar_url = http://myavatarserver.com/getbyemail/{email}/{size}
+#alternative_gravatar_url = http://myavatarserver.com/getbymd5/{md5email}?s={size}
 
 container_auth_enabled = false
 proxypass_auth_enabled = false
--- a/rhodecode/lib/helpers.py	Tue Aug 28 09:04:02 2012 +0200
+++ b/rhodecode/lib/helpers.py	Tue Aug 28 09:05:27 2012 +0200
@@ -713,9 +713,12 @@
 def gravatar_url(email_address, size=30):
     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}
+        tmpl = config['app_conf'].get('alternative_gravatar_url', '')
+        tmpl = tmpl.replace('{email}', email_address)\
+                   .replace('{md5email}', hashlib.md5(email_address.lower()).hexdigest())\
+                   .replace('{size}', str(size))
+        return tmpl
+
     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))