Commits

Mike Bayer committed 94a0493

OK! this seems to work for all the issue/browser views, w further testing I'm happy

Comments (0)

Files changed (2)

tracvatar/htdocs/tracvatar.css

 img.tracvatar.ticket-reporter {
   float:left;
   padding:0 10px 10px 0px;
+}
+
+img.tracvatar.browser-lineitem {
+  padding:0 3px 0 0;
+}
+
+img.tracvatar.browser-changeset {
+  padding:3px 5px 0px 0px;
 }

tracvatar/web_ui.py

     ticket_reporter_size = Option("tracvatar", "ticket_reporter_size", default="60")
     ticket_comment_size = Option("tracvatar", "ticket_comment_size", default="40")
     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")
 
     default = Option('tracvatar', 'gravatar_default', default='default',
                             doc="The default value to pass along to gravatar to "
             filter_.append(self._ticket_comment_filter(data, author_data))
         elif req.path_info.startswith("/timeline"):
             filter_.append(self._timeline_filter(data, author_data))
+        elif req.path_info.startswith("/browser"):
+            filter_.append(self._browser_filter(data, author_data))
+        elif req.path_info.startswith("/log"):
+            filter_.append(self._log_filter(data, author_data))
 
         self._lookup_email(author_data)
         for f in filter_:
     def get_templates_dirs(self):
         return []
 
-    def _node_attrs(self, node):
-        """given a genshi node in a stream, return a dictionary of the 
-        'attrs' portion."""
-
-        return dict([(str(qname), value) for qname, value in node[1][1]])
-
     def _generate_avatar(self, author, author_data, class_, size):
-        email_hash = author_data[author] or author
+        email_hash = author_data.get(author, None) or 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"
             href += "&default=%s" % (self.default,)
         return tag.img(src=href, class_='tracvatar %s' % class_).generate()
 
+    def _browser_filter(self, data, author_data):
+        if not data.get('dir'):
+            return self._browser_changeset_filter(data, author_data)
+        else:
+            return self._browser_lineitem_filter(data, author_data)
+
+    def _browser_changeset_filter(self, data, author_data):
+        if 'file' not in data or 'changeset' not in data['file']:
+            return
+        author = data['file']['changeset'].author
+        author_data[author]  = None
+        return lambda stream: Transformer('//table[@id="info"]//th').prepend(
+            self._generate_avatar(
+                    author, 
+                    author_data, 
+                    "browser-changeset", 
+                    self.browser_changeset_size)
+        )(stream)
+
+    def _log_filter(self, data, author_data):
+        if 'changes' not in data:
+            return
+        for change in data['changes'].values():
+            author_data[change.author] = None
+        return self._browser_lineitem_render_filter(author_data)
+
+    def _browser_lineitem_filter(self, data, author_data):
+        if 'dir' not in data or 'changes' not in data['dir']:
+            return
+        for trac_cset in data['dir']['changes'].values():
+            author_data[trac_cset.author] = None
+        return self._browser_lineitem_render_filter(author_data)
+
+    def _browser_lineitem_render_filter(self, author_data):
+        def find_change(stream):
+            author = stream[1][1]
+            tag = self._generate_avatar(
+                author,
+                author_data,
+                'browser-lineitem',
+                self.browser_lineitem_size)
+            return itertools.chain([stream[0]], tag, stream[1:])
+
+        return Transformer('//td[@class="author"]').filter(find_change)
+
     def _ticket_reporter_filter(self, data, author_data):
         if 'ticket' not in data:
             return