changeset 1024:0849d0697d31

user avatar, from gravatar
author "Luis Henrique Fagundes <lhfagundes@gmail.com>"
date Sun, 30 Oct 2011 05:14:40 -0200
parents 80043704f37e
children 81d30cb55b68
files MoinMoin/templates/layout.html MoinMoin/user.py
diffstat 2 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/templates/layout.html	Sun Oct 30 01:16:40 2011 -0200
+++ b/MoinMoin/templates/layout.html	Sun Oct 30 05:14:40 2011 -0200
@@ -36,6 +36,9 @@
 
     <div id="moin-username">
         {% if user.valid -%}
+	    {% if user.avatar %}
+	        <img id="moin-avatar" src="{{ user.avatar }}" />
+	    {%- endif %}
             {% if user.name -%}
                 {% set wiki_href, aliasname, title, exists = theme_supp.userhome() %}
                 <a href="{{ wiki_href }}" {% if not exists %}class="moin-nonexistent"{% endif %} rel="nofollow" title="{{ title }}">
--- a/MoinMoin/user.py	Sun Oct 30 01:16:40 2011 -0200
+++ b/MoinMoin/user.py	Sun Oct 30 05:14:40 2011 -0200
@@ -21,6 +21,8 @@
 
 import time
 import copy
+import hashlib
+import urllib
 from StringIO import StringIO
 
 from babel import parse_locale
@@ -259,6 +261,27 @@
                 pass
         return l
 
+    @property
+    def avatar(self, size=30):
+        param = {}
+        if not self.email:
+            return '/_themes/%s/%s' % (theme.info['identifier'],
+                                       theme.info['default_avatar'] or 'img/default_avatar.png')
+        param['gravatar_id'] = hashlib.md5(self.email.lower()).hexdigest()
+
+        from MoinMoin.themes import get_current_theme
+        theme = get_current_theme()
+        if theme.info.get('default_avatar'):
+            param['default'] = '%s_themes/%s/%s' % (request.url_root,
+                                                    theme.info['identifier'],
+                                                    theme.info['default_avatar'])
+
+        param['size'] = str(size)
+        gravatar_url = "http://www.gravatar.com/avatar.php?"
+        gravatar_url += urllib.urlencode(param)
+
+        return gravatar_url
+
     def create_or_update(self, changed=False):
         """ Create or update a user profile