Commits

Mike Bayer committed bc7b4f2

- Detect if https:// is in use, generate
https:// Gravatars in this case.

Comments (0)

Files changed (3)

+1.5
+---
+
+- Detect if https:// is in use, generate 
+  https:// Gravatars in this case.
+
 1.4
 ---
 

tracvatar/__init__.py

-__version__ = '1.4'
+__version__ = '1.5'

tracvatar/web_ui.py

     def filter_stream(self, req, method, filename, stream, data):
         filter_ = []
         author_data = {}
+        context = dict(
+            is_https = req.base_url.startswith("https://"),
+            author_data = author_data,
+            data = data
+        )
         if req.path_info.startswith("/ticket"):
-            filter_.append(self._ticket_reporter_filter(data, author_data))
-            filter_.append(self._ticket_comment_filter(data, author_data))
+            filter_.append(self._ticket_reporter_filter(context))
+            filter_.append(self._ticket_comment_filter(context))
         elif req.path_info.startswith("/timeline"):
-            filter_.append(self._timeline_filter(data, author_data))
+            filter_.append(self._timeline_filter(context))
         elif req.path_info.startswith("/browser"):
-            filter_.append(self._browser_filter(data, author_data))
+            filter_.append(self._browser_filter(context))
         elif req.path_info.startswith("/log"):
-            filter_.append(self._log_filter(data, author_data))
+            filter_.append(self._log_filter(context))
         elif req.path_info == "/prefs":
-            filter_.append(self._prefs_filter(data, author_data))
+            filter_.append(self._prefs_filter(context))
 
         filter_.append(self._footer())
         self._lookup_email(author_data)
             class_="left",
         ))
 
-    def _generate_avatar(self, author, author_data, class_, size):
+    def _generate_avatar(self, context, author, class_, size):
+        author_data = context['author_data']
         email_hash = author_data.get(author, None) or self._gravatar(author)
-        href = "http://www.gravatar.com/avatar/" + email_hash
+        if context['is_https']:
+            href = "https://gravatar.com/avatar/" + email_hash
+        else:
+            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_, width=size, height=size).generate()
 
-    def _browser_filter(self, data, author_data):
+    def _browser_filter(self, context):
+        data, author_data = context['data'], context['author_data']
         if not data.get('dir'):
-            return self._browser_changeset_filter(data, author_data)
+            return self._browser_changeset_filter(context)
         else:
-            return self._browser_lineitem_filter(data, author_data)
+            return self._browser_lineitem_filter(context)
 
-    def _browser_changeset_filter(self, data, author_data):
+    def _browser_changeset_filter(self, context):
+        data, author_data = context['data'], context['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(
+                    context,
                     author, 
-                    author_data, 
                     "browser-changeset", 
                     self.browser_changeset_size)
         )(stream)
 
-    def _prefs_filter(self, data, author_data):
+    def _prefs_filter(self, context):
+        data, author_data = context['data'], context['author_data']
         if 'settings' not in data or \
             'session' not in data['settings'] or \
             'email' not in data['settings']['session']:
                 ),
                 tag.td(
                     self._generate_avatar(
+                         context,
                          email,
-                         author_data,
                          "prefs-gravatar",
                          self.prefs_form_size
                     ),
             )
         )
 
-    def _log_filter(self, data, author_data):
+    def _log_filter(self, context):
+        data, author_data = context['data'], context['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)
+        return self._browser_lineitem_render_filter(context)
 
-    def _browser_lineitem_filter(self, data, author_data):
+    def _browser_lineitem_filter(self, context):
+        data, author_data = context['data'], context['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)
+        return self._browser_lineitem_render_filter(context)
 
-    def _browser_lineitem_render_filter(self, author_data):
+    def _browser_lineitem_render_filter(self, context):
+        data, author_data = context['data'], context['author_data']
         def find_change(stream):
             author = stream[1][1]
             tag = self._generate_avatar(
+                context,
                 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):
+    def _ticket_reporter_filter(self, context):
+        data, author_data = context['data'], context['author_data']
         if 'ticket' not in data:
             return
         author = data['ticket'].values['reporter']
         return lambda stream: Transformer('//div[@id="ticket"]').\
                     prepend(
                         self._generate_avatar(
+                            context,
                             author, 
-                            author_data, 
                             'ticket-reporter', 
                             self.ticket_reporter_size)
                         )(stream)
 
-    def _ticket_comment_filter(self, data, author_data):
+    def _ticket_comment_filter(self, context):
+        data, author_data = context['data'], context['author_data']
         if 'changes' not in data:
             return
 
             stream = iter(stream)
             author = apply_authors.pop()
             tag = self._generate_avatar(
+                        context,
                         author, 
-                        author_data, 
                         'ticket-comment', 
                         self.ticket_comment_size)
             return itertools.chain([next(stream)], tag, stream)
         return Transformer('//div[@id="changelog"]/div[@class="change"]/h3[@class="change"]').\
                         filter(find_change)
 
-    def _timeline_filter(self, data, author_data):
+    def _timeline_filter(self, context):
+        data, author_data = context['data'], context['author_data']
         if 'events' not in data:
             return
         apply_authors = []
             stream = iter(stream)
             author = apply_authors.pop()
             tag = self._generate_avatar(
+                        context,
                         author, 
-                        author_data, 
                         'timeline', 
                         self.timeline_size)
             return itertools.chain(tag, stream)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.