incubator-bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g..@apache.org
Subject svn commit: r1294676 - /incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/ticket_web_ui.py
Date Tue, 28 Feb 2012 14:45:52 GMT
Author: gjm
Date: Tue Feb 28 14:45:51 2012
New Revision: 1294676

URL: http://svn.apache.org/viewvc?rev=1294676&view=rev
Log:
overriding search source methods for tickets to attempt to take product specification into
account

Modified:
    incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/ticket_web_ui.py

Modified: incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/ticket_web_ui.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/ticket_web_ui.py?rev=1294676&r1=1294675&r2=1294676&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/ticket_web_ui.py (original)
+++ incubator/bloodhound/trunk/bloodhound_multiproduct/multiproduct/ticket_web_ui.py Tue Feb
28 14:45:51 2012
@@ -16,13 +16,18 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-""" Multi product support for tickets """
+""" Multi product support for tickets."""
 
 import re
 
 from trac.core import TracError
 from trac.ticket.web_ui import TicketModule
-from trac.util.translation import _
+from trac.attachment import AttachmentModule
+from trac.ticket.api import TicketSystem
+from trac.resource import Resource, get_resource_shortname
+from trac.search import search_to_sql, shorten_result
+from trac.util.datefmt import from_utimestamp
+from trac.util.translation import _, tag_
 from genshi.builder import tag
 
 from model import Product
@@ -38,8 +43,10 @@ class ProductTicketModule(TicketModule):
         match = PRODUCT_RE.match(req.path_info)
         if match:
             pid = match.group('pid')
-            if Product.select(self.env, where={'prefix':pid}):
-                req.args['product'] = 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')
                 # is it a newticket request:
                 if pathinfo == "/newticket":
@@ -61,15 +68,67 @@ class ProductTicketModule(TicketModule):
     # INavigationContributor methods
     
     #def get_active_navigation_item(self, req):
-    # override not required
+    # override not yet required
 
     def get_navigation_items(self, req):
         """Overriding TicketModules New Ticket nav item"""
         if 'TICKET_CREATE' in req.perm:
-            product = req.args.get('product','')
+            product = req.args.get('productid','')
             if product:
                 href = req.href.__getattr__(product)('newticket')
             else:
                 href = req.href.newticket()
             yield ('mainnav', 'newticket', 
                    tag.a(_("New Ticket"), href=href, accesskey=7))
+    
+    # ISearchSource methods
+    #def get_search_filters(self, req):
+    # override not yet required
+    
+    def get_search_results(self, req, terms, filters):
+        """Overriding search results for Tickets"""
+        if not 'ticket' in filters:
+            return
+        ticket_realm = Resource('ticket')
+        with self.env.db_query as db:
+            sql, args = search_to_sql(db, ['summary', 'keywords',
+                                           'description', 'reporter', 'cc', 
+                                           db.cast('id', 'text')], terms)
+            sql2, args2 = search_to_sql(db, ['newvalue'], terms)
+            sql3, args3 = search_to_sql(db, ['value'], terms)
+            ticketsystem = TicketSystem(self.env)
+            if req.args.get('product'):
+                productsql = "product='%s' AND" % req.args.get('product')
+            else:
+                productsql = ""
+            
+            for summary, desc, author, type, tid, ts, status, resolution in \
+                    db("""SELECT summary, description, reporter, type, id,
+                                 time, status, resolution 
+                          FROM ticket
+                          WHERE (%s id IN (
+                              SELECT id FROM ticket WHERE %s
+                            UNION
+                              SELECT ticket FROM ticket_change
+                              WHERE field='comment' AND %s
+                            UNION
+                              SELECT ticket FROM ticket_custom WHERE %s
+                          ))
+                          """ % (productsql, sql, sql2, sql3),
+                          args + args2 + args3):
+                t = ticket_realm(id=tid)
+                if 'TICKET_VIEW' in req.perm(t):
+                    yield (req.href.ticket(tid),
+                           tag_("%(title)s: %(message)s",
+                                title=tag.span(
+                                    get_resource_shortname(self.env, t),
+                                    class_=status),
+                                message=ticketsystem.format_summary(
+                                    summary, status, resolution, type)),
+                           from_utimestamp(ts), author,
+                           shorten_result(desc, terms))
+        
+        # Attachments
+        for result in AttachmentModule(self.env).get_search_results(
+            req, ticket_realm, terms):
+            yield result



Mime
View raw message