Anonymous avatar Anonymous committed 6121cdc Draft

provides an override for the ReportModule; small refactor to separate out common determination of the product from the path

Comments (0)

Files changed (4)

multiproduct/__init__.py

 from model import MultiProductEnvironmentProvider
 from product_admin import ProductAdminPanel
 import multiproduct.ticket
+import common

multiproduct/common.py

+
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+
+import re
+
+from multiproduct.model import Product
+
+PRODUCT_RE = re.compile(r'^/(?P<pid>[^/]*)(?P<pathinfo>.*)')
+
+def match_product_path(env, req):
+    """Matches a product in pathinfo, stores the associated product id and
+    returns what is left"""
+    pathinfo = req.path_info[:]
+    match = PRODUCT_RE.match(pathinfo)
+    if match:
+        pid = match.group('pid')
+        products = Product.select(env, where={'prefix':pid})
+        if len(products) == 1:
+            req.args['productid'] = match.group('pid')
+            req.args['product'] = products[0].name
+            pathinfo = match.group('pathinfo')
+    return pathinfo

multiproduct/ticket/__init__.py

 #  under the License.
 
 """multiproduct ticket related functionality and overrides"""
-from web_ui import ProductTicketModule
-from api import ProductTicketFields
+from web_ui import ProductTicketModule, ProductReportModule
+from api import ProductTicketFields

multiproduct/ticket/web_ui.py

 
 from trac.core import TracError
 from trac.ticket.web_ui import TicketModule
+from trac.ticket.report import ReportModule
 from trac.attachment import AttachmentModule
 from trac.ticket.api import TicketSystem
 from trac.resource import Resource, get_resource_shortname
 from trac.util.translation import _, tag_
 from genshi.builder import tag
 
-from multiproduct.model import Product
+from multiproduct.common import match_product_path
 
-PRODUCT_RE = re.compile(r'^/(?P<pid>[^/]*)(?P<pathinfo>.*)')
 TICKET_RE = re.compile(r'/ticket/(?P<ticket>[0-9]+)$')
+REPORT_RE = re.compile(r'/report(?:/(?:([0-9]+)|-1))?$')
+
 class ProductTicketModule(TicketModule):
     """Product Overrides for the TicketModule"""
     
     # IRequestHandler methods
     def match_request(self, req):
         """Override of TicketModule match_request"""
-        pathinfo = req.path_info[:]
-        match = PRODUCT_RE.match(pathinfo)
-        if match:
-            pid = match.group('pid')
-            products = Product.select(self.env, where={'prefix':pid})
-            if len(products) == 1:
-                req.args['productid'] = match.group('pid')
-                req.args['product'] = products[0].name
-                pathinfo = match.group('pathinfo')
-            
+        pathinfo = match_product_path(self.env, req)
         # is it a newticket request:
         if pathinfo == "/newticket":
             return True
         for result in AttachmentModule(self.env).get_search_results(
             req, ticket_realm, terms):
             yield result
+
+class ProductReportModule(ReportModule):
+    """replacement for ReportModule"""
+    
+    # IRequestHandler methods
+    def match_request(self, req):
+        """Override of ReportModule match_request"""
+        pathinfo = match_product_path(self.env, req)
+        match = REPORT_RE.match(pathinfo)
+        if match:
+            if match.group(1):
+                req.args['id'] = match.group(1)
+            return True
+    
+    #def process_request(self, req):
+    # not yet required
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.