Ticket #3226: autoquery_patch_vs_r7289.txt

File autoquery_patch_vs_r7289.txt, 3.7 kB (added by k0s, 6 months ago)

simple patch to trac core

Line 
1 Index: web_ui.py
2 ===================================================================
3 --- web_ui.py   (revision 7289)
4 +++ web_ui.py   (working copy)
5 @@ -21,6 +21,7 @@
6  import re
7  from StringIO import StringIO
8  import time
9 +import urllib
10  
11  from genshi.core import Markup
12  from genshi.builder import tag
13 @@ -105,7 +106,14 @@
14          If set to 'default', this is equivalent to 'yes' for new environments
15          but keeps the old behavior for upgraded environments (i.e. 'no').
16          (''since 0.11'').""")
17 +   
18 +    query_args = Option('autoquery', 'query_args', default='&order=priority',
19 +                        doc="additional arguments to the query string")
20  
21 +    excluded_fields = Option('autoquery', 'excluded_fields',
22 +                             default=['estimatedhours', 'hours', 'totalhours'],
23 +                             doc="fields to exclude from AutoQuery markup")
24 +
25      # IContentConverter methods
26  
27      def get_supported_conversions(self):
28 @@ -557,10 +565,23 @@
29          if preserve_newlines == 'default':
30              preserve_newlines = self.env.get_version(initial=True) >= 21 # 0.11
31          preserve_newlines = preserve_newlines in _TRUE_VALUES
32 +       
33 +        query = self.env.href() + '/query?%s=%s' + self.query_args
34 +        def query_link(x, y):
35 +            try:
36 +                y = urllib.quote_plus(y)
37 +            except KeyError:
38 +                # XXX work around bug with urllib + unicode
39 +                # see http://trac-hacks.org/ticket/3157
40 +                y = y.replace(' ', '+')
41 +            return query % ( x, y )
42 +
43          return {'ticket': ticket,
44                  'context': Context.from_request(req, ticket.resource,
45                                                  absurls=absurls),
46 -                'preserve_newlines': preserve_newlines}
47 +                'preserve_newlines': preserve_newlines,
48 +                'query_link': query_link,
49 +                'excluded_fields': self.excluded_fields }
50  
51      def _toggle_cc(self, req, cc):
52          """Return an (action, recipient) tuple corresponding to a change
53 Index: templates/ticket.html
54 ===================================================================
55 --- templates/ticket.html       (revision 7289)
56 +++ templates/ticket.html       (working copy)
57 @@ -135,9 +135,16 @@
58                                      not in ('type', 'owner')]">
59              <tr>
60                <th id="h_reporter">Reported by:</th>
61 -              <td headers="h_reporter" class="searchable">${authorinfo(ticket.reporter)}</td>
62 +              <td headers="h_reporter" class="searchable">
63 +               <a href="${query_link('reporter', ticket.reporter)}">
64 +                 ${authorinfo(ticket.reporter)}
65 +               </a>
66 +             </td>
67                <th id="h_owner">Owned by:</th>
68 -              <td headers="h_owner">${ticket.owner and authorinfo(ticket.owner) or ''}
69 +              <td headers="h_owner">
70 +               <a href="${query_link('owner', ticket.owner)}">
71 +                 ${ticket.owner and authorinfo(ticket.owner) or ''}
72 +               </a>
73                </td>
74              </tr>
75              <tr py:for="row in group(fields, 2, lambda f: f.type != 'textarea')"
76 @@ -154,7 +161,18 @@
77                    <py:if test="field">
78                      <py:choose test="">
79                        <py:when test="'rendered' in field">${field.rendered}</py:when>
80 -                      <py:otherwise>${ticket[field.name]}</py:otherwise>
81 +                      <py:otherwise>
82 +                       <py:if test="ticket[field.name]">
83 +                         <py:if test="field.name not in excluded_fields">
84 +                           <a href="${query_link(field.name, ticket[field.name])}">
85 +                             ${ticket[field.name]}
86 +                           </a>
87 +                         </py:if>
88 +                         <py:if test="field.name in excluded_fields">
89 +                           ${ticket[field.name]}
90 +                         </py:if>
91 +                       </py:if>
92 +                     </py:otherwise>
93                      </py:choose>
94                    </py:if>
95                  </td>