Commits

Anonymous committed 5d21219

0.13dev: Merged from 0.12-stable.

Comments (0)

Files changed (2)

trac/ticket/query.py

                     if val[:1] in ('~', '^', '$') \
                                         and not val in self.substitutions:
                         mode, val = val[:1], val[1:]
-                    val = val.replace('$USER', req.authname)
+                    if req:
+                        val = val.replace('$USER', req.authname)
                     constraint['mode'] = ('!' if neg else '') + mode
                     constraint['values'].append(val)
                 constraints[k] = constraint
         tickets = query.execute(req)
 
         if format == 'table':
-            data = query.template_data(formatter.context, tickets)
+            data = query.template_data(formatter.context, tickets,
+                                       req=formatter.context.req)
 
             add_stylesheet(req, 'common/css/report.css')
             

trac/ticket/tests/query.py

         self.assertEqual('\xef\xbb\xbfcol1\r\n"value, needs escaped"\r\n',
                          content)
 
+    def test_template_data(self):
+        req = Mock(href=self.env.href, perm=MockPerm(), authname='anonymous',
+                   tz=None, locale=None)
+        context = web_context(req, 'query')
+
+        query = Query.from_string(self.env, 'owner=$USER&order=id')
+        tickets = query.execute(req)
+        data = query.template_data(context, tickets, req=req)
+        self.assertEqual(['anonymous'], data['clauses'][0]['owner']['values'])
+
+        query = Query.from_string(self.env, 'owner=$USER&order=id')
+        tickets = query.execute(req)
+        data = query.template_data(context, tickets)
+        self.assertEqual(['$USER'], data['clauses'][0]['owner']['values'])
+
 
 class QueryLinksTestCase(unittest.TestCase):