Commits

hacklab committed 8aa994c

avatar checks better now: proper url and not crashing if user has no e-mail

  • Participants
  • Parent commits cc66571

Comments (0)

Files changed (2)

File MoinMoin/templates/layout.html

 
     <div id="moin-username">
         {% if user.valid -%}
-	    {% if user.avatar %}
-	        <img id="moin-avatar" src="{{ user.avatar }}" />
+	    {% set avatar = user.avatar(20) %}
+	    {% if avatar %}
+	        <img id="moin-avatar" src="{{ avatar }}" />
 	    {%- endif %}
             {% if user.name -%}
                 {% set wiki_href, aliasname, title, exists = theme_supp.userhome() %}

File MoinMoin/user.py

 import time
 import copy
 import hashlib
-import urllib
+import werkzeug
 from StringIO import StringIO
 
 from babel import parse_locale
                 pass
         return l
 
-    @property
     def avatar(self, size=30):
         if not app.cfg.user_use_gravatar:
-            return ''
+            return None
+
+        from MoinMoin.themes import get_current_theme
+        from flask.ext.themes import static_file_url
+        
+        theme = get_current_theme()
+
+        if not self.email:
+            return static_file_url(theme, theme.info.get('default_avatar', 'img/default_avatar.png'))
+
         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['default'] = static_file_url(theme,
+                                           theme.info.get('default_avatar', 'img/default_avatar.png'),
+                                           True)
 
         param['size'] = str(size)
+        #TODO: use same protocol of Moin site (might be https instead of http)]
         gravatar_url = "http://www.gravatar.com/avatar.php?"
-        gravatar_url += urllib.urlencode(param)
+        gravatar_url += werkzeug.url_encode(param)
 
         return gravatar_url