Commits

Olemis Lang committed 95681a8

BH Theme #583 : Specify template overrides for Bloodhound theme [BUGGY]

Comments (0)

Files changed (2)

+t583/t583_r1502480_template_overrides.diff

t583/t583_r1502480_template_overrides.diff

+# HG changeset patch
+# Parent ebadc9393b2878c43e4529f7afa969d74529e0a1
+BH Theme #583 : Template overrides powered by trachacks:ThemeEnginePlugin>=2.2.0
+
+diff -r ebadc9393b28 bloodhound_theme/bhtheme/theme.py
+--- a/bloodhound_theme/bhtheme/theme.py	Fri Jul 12 08:51:54 2013 +0000
++++ b/bloodhound_theme/bhtheme/theme.py	Fri Jul 12 13:17:48 2013 -0500
+@@ -151,7 +151,7 @@
+         ("body//table[not(contains(@class, 'table'))]",  # TODO: Accurate ?
+          ['table', 'table-condensed']),
+     )
+-    
++
+     labels_application_short = Option('labels', 'application_short', 
+         'Bloodhound', """A short version of application name most commonly 
+         displayed in text, titles and labels""")
+@@ -159,13 +159,13 @@
+     labels_application_full = Option('labels', 'application_full', 
+         'Apache Bloodhound', """This is full name with trade mark and 
+         everything, it is currently used in footers and about page only""")
+-    
++
+     labels_footer_left_prefix = Option('labels', 'footer_left_prefix', '', 
+         """Text to display before full application name in footers""")
+ 
+     labels_footer_left_postfix = Option('labels', 'footer_left_postfix', '', 
+         """Text to display after full application name in footers""")
+-    
++
+     labels_footer_right = Option('labels', 'footer_right', '',
+         """Text to use as the right aligned footer""")
+ 
+@@ -189,6 +189,14 @@
+             'application_version': application_version
+         }
+ 
++    # IThemeProvider methods
++
++    def get_template_overrides(name):
++        """List templates overriden by Bloodhoud theme.
++        """
++        for old, (new, fnm) in self.BLOODHOUND_TEMPLATE_MAP.iteritems():
++            yield old, new, (getattr(self, fnm) if fnm else None)
++
+     # ITemplateStreamFilter methods
+ 
+     def filter_stream(self, req, method, filename, stream, data):
+@@ -210,12 +218,12 @@
+                 self.log.debug('BH Theme : Inserting class ' + out_classes)
+                 return out_classes
+             return attr_modifier
+-        
++
+         # Insert default bootstrap CSS classes if necessary
+         for xpath, classes in self.BOOTSTRAP_CSS_DEFAULTS:
+             tx = tx.end().select(xpath) \
+                 .attr('class', add_classes(classes))
+-         
++
+         # Rename wiki guide links
+         tx = tx.end() \
+             .select("body//a[contains(@href,'/wiki/%s')]" % wiki.GUIDE_NAME) \
+@@ -226,7 +234,7 @@
+         tx = tx.end() \
+             .select("body//div[@class='error']/h1") \
+             .map(lambda text: text.replace("Trac", app_short), TEXT)
+-                    
++
+         return stream | tx
+ 
+     # IRequestFilter methods
+@@ -249,24 +257,16 @@
+             return req.href.__call__("wiki", *a, **kw)
+ 
+         req.href.wiki = hwiki
+-        
++
+         return handler
+ 
+     def post_process_request(self, req, template, data, content_type):
+         """Post process request filter.
+         Removes all trac provided css if required"""
+-        
++
+         if template is None and data is None and \
+                 sys.exc_info() == (None, None, None):
+             return template, data, content_type
+-        
+-        def is_active_theme():
+-            is_active = False
+-            active_theme = ThemeEngineSystem(self.env).theme
+-            if active_theme is not None:
+-                this_theme_name = self.get_theme_names().next()
+-                is_active = active_theme['name'] == this_theme_name
+-            return is_active
+ 
+         req.chrome['labels'] = self._get_whitelabelling()
+ 
+@@ -284,8 +284,8 @@
+                 links.get('icon')[0].update(new_icon)
+             if links.get('shortcut icon'):
+                 links.get('shortcut icon')[0].update(new_icon)
+-        
+-        is_active_theme = is_active_theme()
++
++        is_active_theme = self.is_active_theme
+         if self.disable_all_trac_css and is_active_theme:
+             if self.disable_all_trac_css:
+                 stylesheets = links.get('stylesheet', [])
+@@ -295,11 +295,6 @@
+                     links['stylesheet'] = \
+                         [ss for ss, href in _iter if not path in href or
+                          href.rsplit('/', 1)[-1] in self.BLOODHOUND_KEEP_CSS]
+-            template, modifier = \
+-                self.BLOODHOUND_TEMPLATE_MAP.get(template, (template, None))
+-            if modifier is not None:
+-                modifier = getattr(self, modifier)
+-                modifier(req, template, data, content_type, is_active_theme)
+ 
+         if is_active_theme and data is not None:
+             data['responsive_layout'] = \
+@@ -328,39 +323,34 @@
+ 
+     # Request modifiers
+ 
+-    def _modify_search_data(self, req, template, data, content_type, is_active):
++    def _modify_search_data(self, req, template, data, content_type):
+         """Insert breadcumbs and context navigation items in search web UI
+         """
+-        if is_active:
+-            # Insert query string in search box (see bloodhound_theme.html)
+-            req.search_query = data.get('query')
+-            # Context nav
+-            prevnext_nav(req, _('Previous'), _('Next'))
++        # Insert query string in search box (see bloodhound_theme.html)
++        req.search_query = data.get('query')
++        # Context nav
++        prevnext_nav(req, _('Previous'), _('Next'))
+         # Breadcrumbs nav
+         data['resourcepath_template'] = 'bh_path_search.html'
+ 
+-    def _modify_wiki_page_path(self, req, template, data, content_type,
+-                               is_active):
++    def _modify_wiki_page_path(self, req, template, data, content_type):
+         """Override wiki breadcrumbs nav items
+         """
+-        if is_active:
+-            data['resourcepath_template'] = 'bh_path_wikipage.html'
++        data['resourcepath_template'] = 'bh_path_wikipage.html'
+ 
+-    def _modify_roadmap_page(self, req, template, data, content_type,
+-                             is_active):
++    def _modify_roadmap_page(self, req, template, data, content_type):
+         """Insert roadmap.css + products breadcrumb
+         """
+         add_stylesheet(req, 'dashboard/css/roadmap.css')
+         self._add_products_general_breadcrumb(req, template, data,
+-                                              content_type, is_active)
++                                              content_type)
+         data['milestone_list'] = [m.name for m in Milestone.select(self.env)]
+         req.chrome['ctxtnav'] = []
+ 
+-    def _modify_ticket(self, req, template, data, content_type, is_active):
++    def _modify_ticket(self, req, template, data, content_type):
+         """Ticket modifications
+         """
+-        self._modify_resource_breadcrumb(req, template, data, content_type,
+-                                         is_active)
++        self._modify_resource_breadcrumb(req, template, data, content_type)
+ 
+         #add a creation event to the changelog if the ticket exists
+         if data['ticket'].exists:
+@@ -377,8 +367,7 @@
+         if not req.session.get('ticket_comments_order'):
+             req.session['ticket_comments_order'] = 'newest'
+ 
+-    def _modify_resource_breadcrumb(self, req, template, data, content_type,
+-                                    is_active):
++    def _modify_resource_breadcrumb(self, req, template, data, content_type):
+         """Provides logic for breadcrumb resource permissions
+         """
+         if data and ('ticket' in data.keys()) and data['ticket'].exists:
+@@ -396,7 +385,7 @@
+             if mname:
+                 data['milestone'] = Milestone(self.env, mname)
+ 
+-    def _modify_admin_breadcrumb(self, req, template, data, content_type, is_active):
++    def _modify_admin_breadcrumb(self, req, template, data, content_type):
+         # override 'normal' product list with the admin one
+         glsettings = (None, _('(Global settings)'), req.href.admin())
+         admin_url = lambda x: req.href.products(x, 'admin')
+@@ -412,7 +401,7 @@
+             data['admin_current_product'] = glsettings
+         data['resourcepath_template'] = 'bh_path_general.html'
+ 
+-    def _modify_browser(self, req, template, data, content_type, is_active):
++    def _modify_browser(self, req, template, data, content_type):
+         """Locate path to file in breadcrumbs area rather than title.
+         Add browser-specific CSS.
+         """
+@@ -423,7 +412,7 @@
+         add_stylesheet(req, 'theme/css/browser.css')
+ 
+     def _add_products_general_breadcrumb(self, req, template, data,
+-                                         content_type, is_active):
++                                         content_type):
+         data['resourcepath_template'] = 'bh_path_general.html'
+ 
+     # INavigationContributor methods
+diff -r ebadc9393b28 bloodhound_theme/setup.py
+--- a/bloodhound_theme/setup.py	Fri Jul 12 08:51:54 2013 +0000
++++ b/bloodhound_theme/setup.py	Fri Jul 12 13:17:48 2013 -0500
+@@ -36,7 +36,8 @@
+   classifiers = [
+       'Framework :: Trac',
+     ],
+-  install_requires = ['BloodhoundDashboardPlugin', 'TracThemeEngine', 'Trac'],
++  install_requires = ['BloodhoundDashboardPlugin', 'TracThemeEngine>=2.2.0', 
++                      'Trac'],
+   tests_require = ['unittest2'] if sys.version_info < (2, 7) else [],
+   entry_points = {
+       'trac.plugins': [