Commits

Mike Bayer  committed ce4569b

add prefs display

  • Participants
  • Parent commits 50c6984

Comments (0)

Files changed (2)

File tracvatar/htdocs/tracvatar.css

 
 img.tracvatar.browser-changeset {
   padding:3px 5px 0px 0px;
+}
+
+td.tracvatar.prefs-gravatar {
+  vertical-align:middle;
+  white-space:nowrap;
 }

File tracvatar/web_ui.py

     timeline_size = Option("tracvatar", "timeline_size", default="30")
     browser_lineitem_size = Option("tracvatar", "browser_lineitem_size", default="20")
     browser_changeset_size = Option("tracvatar", "browser_changeset_size", default="40")
+    prefs_form_size = Option("tracvatar", "prefs_form_size", default="40")
 
     default = Option('tracvatar', 'gravatar_default', default='default',
                             doc="The default value to pass along to gravatar to "
             filter_.append(self._browser_filter(data, author_data))
         elif req.path_info.startswith("/log"):
             filter_.append(self._log_filter(data, author_data))
+        elif req.path_info == "/prefs":
+            filter_.append(self._prefs_filter(data, author_data))
 
         filter_.append(self._footer())
         self._lookup_email(author_data)
         ))
 
     def _generate_avatar(self, author, author_data, class_, size):
-        email_hash = author_data.get(author, None) or author
+        email_hash = author_data.get(author, None) or self._gravatar(author)
         href = "http://www.gravatar.com/avatar/" + email_hash
         href += "?size=%s" % size
         # for some reason sizing doesn't work if you pass "default=default"
         if self.default != 'default':
             href += "&default=%s" % (self.default,)
-        return tag.img(src=href, class_='tracvatar %s' % class_).generate()
+        return tag.img(src=href, class_='tracvatar %s' % class_, width=size, height=size).generate()
 
     def _browser_filter(self, data, author_data):
         if not data.get('dir'):
                     self.browser_changeset_size)
         )(stream)
 
+    def _prefs_filter(self, data, author_data):
+        if "settings" not in data:
+            return
+
+        email = data['settings']['session']['email']
+
+        return Transformer('//form[@id="userprefs"]/table').append(
+            tag.tr(
+                tag.th(
+                    tag.label(
+                        "Gravatar:",
+                        for_="gravatar"
+                    )
+                ),
+                tag.td(
+                    self._generate_avatar(
+                         email,
+                         author_data,
+                         "prefs-gravatar",
+                         self.prefs_form_size
+                    ),
+                    " Change your avatar at ",
+                    tag.a(
+                        "gravatar.com",
+                        href="http://gravatar.com"
+                    ),
+                    class_="tracvatar prefs-gravatar",
+                ),
+                class_="field"
+            )
+        )
+
     def _log_filter(self, data, author_data):
         if 'changes' not in data:
             return
     # from trac source
     _long_author_re = re.compile(r'.*<([^@]+)@([^@]+)>\s*|([^@]+)@([^@]+)')
 
+    def _gravatar(self, email):
+        return hashlib.md5(email.lower()).hexdigest()
+
     def _lookup_email(self, author_data):
         lookup_authors = sorted([a for a in author_data if '@' not in a])
         if lookup_authors:
                 ), ("email",) + tuple(lookup_authors)
             )
             for sid, email in cursor.fetchall():
-                author_data[sid] = hashlib.md5(email.lower()).hexdigest()
+                author_data[sid] = self._gravatar(email)
 
         for author in set(author_data).difference(lookup_authors):
             author_info = self._long_author_re.match(author)
                     continue
                 author_data[name] = \
                     author_data[author] = \
-                    hashlib.md5(("%s@%s" % (name, host)).lower()).hexdigest()
+                    self._gravatar("%s@%s" % (name, host))