Commits

Mike Bayer  committed fc712b3

renders timeline

  • Participants
  • Parent commits 8c49f7a

Comments (0)

Files changed (1)

File 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")
 
     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("/attachment"):
-            filter_.append(self._attachment_filter(data, author_data))
 
         self._lookup_email(author_data)
         for f in filter_:
         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]
+        email_hash = author_data[author] 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 _attachment_filter(self, data, author_data):
-        if 'attachments' not in data:
-            return
-
     def _ticket_reporter_filter(self, data, author_data):
         if 'ticket' not in data:
             return
         if 'changes' not in data:
             return
 
-        change_data = {}
+        apply_authors = []
         for change in data['changes']:
             author = change['author']
             author_data[author] = None
-            change_data[str(change['cnum'])] = author
+            apply_authors.append(author)
 
         def find_change(stream):
             stream = iter(stream)
-            start_tag = next(stream)
-            attrs = self._node_attrs(start_tag)
-            change = re.match(r'trac\-change\-(\d+)', attrs["id"])
-            if not change:
-                return itertools.chain([start_tag], stream)
-            else:
-                change = change.group(1)
-
-            author = change_data[change]
+            author = apply_authors.pop()
             tag = self._generate_avatar(
                         author, 
                         author_data, 
                         'ticket-comment', 
                         self.ticket_comment_size)
-            stream = Transformer('//h3[@class="change"]').prepend(tag)(stream)
-            return itertools.chain([start_tag], stream)
+            return itertools.chain([next(stream)], tag, stream)
 
-        return Transformer('//div[@id="changelog"]/div[@class="change"]').filter(find_change)
+        return Transformer('//div[@id="changelog"]/div[@class="change"]/h3[@class="change"]').filter(find_change)
+
+    def _timeline_filter(self, data, author_data):
+        if 'events' not in data:
+            return
+        apply_authors = []
+        for event in reversed(data['events']):
+            author = event['author']
+            author_data[author] = None
+            apply_authors.append(author)
+
+        def find_change(stream):
+            stream = iter(stream)
+            author = apply_authors.pop()
+            tag = self._generate_avatar(
+                        author, 
+                        author_data, 
+                        'timeline', 
+                        self.timeline_size)
+            return itertools.chain([next(stream)], tag, stream)
+
+        return Transformer('//div[@id="content"]/dl/dt/a/span[@class="time"]').filter(find_change)
 
     def _lookup_email(self, author_data):
         authors = sorted(author_data)