You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bloodhound.apache.org by gj...@apache.org on 2012/06/20 17:39:15 UTC
svn commit: r1352164 -
/incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/web_ui.py
Author: gjm
Date: Wed Jun 20 15:39:15 2012
New Revision: 1352164
URL: http://svn.apache.org/viewvc?rev=1352164&view=rev
Log:
multiproduct: use a post_process_request to modify nav item links for product links with an exception list - towards #3
Modified:
incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/web_ui.py
Modified: incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/web_ui.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/web_ui.py?rev=1352164&r1=1352163&r2=1352164&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/web_ui.py (original)
+++ incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/web_ui.py Wed Jun 20 15:39:15 2012
@@ -23,6 +23,7 @@ Provides request filtering to capture pr
import re
from genshi.builder import tag
+from genshi.core import Attrs, QName
from trac.core import Component, implements, TracError
from trac.web.chrome import (add_link, add_notice, add_warning, prevnext_nav,
@@ -40,7 +41,11 @@ class ProductModule(Component):
"""Base Product behaviour"""
implements(IRequestFilter, IRequestHandler, INavigationContributor)
-
+ NAVITEM_DO_NOT_TRANSFORM = [ '/dashboard',
+ '/login',
+ '/logout',
+ '/products',
+ ]
def get_active_navigation_item(self, req):
return 'products'
@@ -96,6 +101,28 @@ class ProductModule(Component):
def post_process_request(self, req, template, data, content_type):
"""post process request filter"""
+ # update the nav item links
+ root = req.href()
+ rootproducts = req.href.products()
+ pid = req.args.get('productid')
+ if pid:
+ for navkey, section in req.chrome['nav'].iteritems():
+ for item in section:
+ try:
+ href = item['label'].attrib.get('href')
+ except AttributeError:
+ continue
+ if href.startswith(rootproducts):
+ continue
+ if href.startswith(root):
+ tail = href[len(root):]
+ if tail not in self.NAVITEM_DO_NOT_TRANSFORM:
+ attrs = [attr for attr in item['label'].attrib
+ if attr[0] != 'href']
+ newhref = req.href.products(pid, tail)
+ item['label'].attrib = Attrs([(QName('href'),
+ newhref)] + attrs)
+
return (template, data, content_type)
# IRequestHandler methods