1. Odd Simon Simonsen
  2. trac-t10425

Commits

Odd Simon Simonsen  committed 53c74e8

Further fixes to `default_order` and `default_group` patches. Also handles invalid config settings.

  • Participants
  • Parent commits 87edd16
  • Branches default

Comments (0)

Files changed (2)

File default_group.diff

View file
 # HG changeset patch
-# Parent 51c05f4f7418051ab610b2b6c1538cfb901de235
+# Parent 6216bce8ce8484e5d4f79bbb436e5f94d5d1f53c
 
 diff --git a/trac/ticket/query.py b/trac/ticket/query.py
 --- a/trac/ticket/query.py
 +++ b/trac/ticket/query.py
-@@ -134,8 +134,15 @@
-             else:
-                 (self.order, self.desc) = (default_order, self.desc or 0)
+@@ -135,8 +135,14 @@
+         if self.order != 'id' and self.order not in field_names:
+             (self.order, self.desc) = ('priority', 0)
  
--        if self.group not in field_names:
++        self.group = self.group or QueryModule(self.env).default_group
++        if self.group:
++            if self.group[0] == '-':
++                (self.group, self.groupdesc) = (self.group[1:], 1)
++            elif self.group[0] == '+':
++                (self.group, self.groupdesc) = (self.group[1:], 0)
+         if self.group not in field_names:
 -            self.group = None
-+        if not self.group or self.group not in field_names:
-+            default_group = QueryModule(self.env).default_group or None
-+            if default_group:
-+                if default_group[0] == '-':
-+                    (self.group, self.groupdesc) = (default_group[1:], 1)
-+                elif default_group[0] == '+':
-+                    (self.group, self.groupdesc) = (default_group[1:], 0)
-+                else:
-+                    self.group = default_group
++            (self.group, self.groupdesc) = (None, 0)
  
          constraint_cols = {}
          for clause in self.constraints:
-@@ -416,7 +423,7 @@
+@@ -417,7 +423,7 @@
          return href.query(constraints,
                            report=id,
                            order=order, desc=1 if desc else None,
                            groupdesc=1 if self.groupdesc else None,
                            col=cols,
                            row=self.rows,
-@@ -859,6 +866,10 @@
+@@ -860,6 +866,10 @@
      default_order = Option('query', 'default_order',
          default='priority',
          doc="""The default order to use for queries. (''since 0.13'')""")
 diff --git a/trac/ticket/tests/query.py b/trac/ticket/tests/query.py
 --- a/trac/ticket/tests/query.py
 +++ b/trac/ticket/tests/query.py
-@@ -497,6 +497,68 @@
+@@ -497,6 +497,74 @@
  ORDER BY COALESCE(t.id,0)=0,t.id""")
          self.assertEqual(['anonymous'], args)
          tickets = query.execute(self.req)
 +        self.assertEqual([], args)
 +        tickets = query.execute(self.req)
 +        self.env.config.remove('query', 'default_group')
++
++    def test_default_group_invalid_field(self):
++        self.env.config.set('query', 'default_group', '-foo')
++        query = Query(self.env)
++        self.assertEquals(None, query.group)
++        self.assertEquals(0, query.groupdesc)
  
-     def test_default_orders_no_config_with_request(self):
-         self.env.config.remove('query', 'default_orders')
+     def test_default_order_no_config_with_request(self):
+         self.env.config.remove('query', 'default_order')

File default_order.diff

View file
 # HG changeset patch
-# Parent efb2b2e7af2b9204c99c084dfea6f37a7afde089
+# Parent 8b262cb0aff9d59a6669c9f001a56927184b8610
 
 diff --git a/trac/ticket/query.py b/trac/ticket/query.py
 --- a/trac/ticket/query.py
 +++ b/trac/ticket/query.py
-@@ -126,7 +126,13 @@
+@@ -125,8 +125,15 @@
+         self.cols = [c for c in cols or [] if c in field_names or 
                       c == 'id']
          self.rows = [c for c in rows if c in field_names]
++
++        self.order = self.order or QueryModule(self.env).default_order
++        if self.order:
++            if self.order[0] == '-':
++                (self.order, self.desc) = (self.order[1:], 1)
++            elif self.order[0] == '+':
++                (self.order, self.desc) = (self.order[1:], 0)
          if self.order != 'id' and self.order not in field_names:
 -            self.order = 'priority'
-+            default_order = QueryModule(self.env).default_order or 'priority'
-+            if default_order[0] == '-':
-+                (self.order, self.desc) = (default_order[1:], 1)
-+            elif default_order[0] == '+':
-+                (self.order, self.desc) = (default_order[1:], 0)
-+            else:
-+                (self.order, self.desc) = (default_order, self.desc or 0)
++            (self.order, self.desc) = ('priority', 0)
  
          if self.group not in field_names:
              self.group = None
-@@ -849,6 +855,10 @@
+@@ -849,6 +856,10 @@
          default=None,
          doc="""List of columns to show in query unless defined by the query.
              Default is to let Trac calculate this internally. (''since 0.13'')""")
 diff --git a/trac/ticket/tests/query.py b/trac/ticket/tests/query.py
 --- a/trac/ticket/tests/query.py
 +++ b/trac/ticket/tests/query.py
-@@ -498,6 +498,67 @@
+@@ -498,6 +498,73 @@
          self.assertEqual(['anonymous'], args)
          tickets = query.execute(self.req)
  
-+    def test_default_orders_no_config_with_request(self):
-+        self.env.config.remove('query', 'default_orders')
++    def test_default_order_no_config_with_request(self):
++        self.env.config.remove('query', 'default_order')
 +        query = Query(self.env, order='summary')
 +        sql, args = query.get_sql()
 +        self.assertEqualSQL(sql,
 +        self.assertEqual([], args)
 +        tickets = query.execute(self.req)
 +    
-+    def test_default_orders_no_config_no_request(self):
++    def test_default_order_no_config_no_request(self):
 +        self.env.config.remove('query', 'default_order')
 +        query = Query(self.env)
 +        sql, args = query.get_sql()
 +        self.assertEqual([], args)
 +        tickets = query.execute(self.req)
 +        
-+    def test_default_orders_with_config_with_request(self):
++    def test_default_order_with_config_with_request(self):
 +        self.env.config.set('query', 'default_order', 'type')
 +        query = Query(self.env, order='summary')
 +        sql, args = query.get_sql()
 +        tickets = query.execute(self.req)
 +        self.env.config.remove('query', 'default_orders')
 +        
-+    def test_default_orders_with_config_no_request(self): 
++    def test_default_order_with_config_no_request(self): 
 +        self.env.config.set('query', 'default_order', 'time')
 +        query = Query(self.env)
 +        sql, args = query.get_sql()
 +        tickets = query.execute(self.req)
 +        self.env.config.remove('query', 'default_order')
 +
++    def test_default_order_invalid_field(self):
++        self.env.config.set('query', 'default_order', '-foo')
++        query = Query(self.env)
++        self.assertEquals('priority', query.order)
++        self.assertEquals(0, query.desc)
++
      def test_default_cols_with_config_no_request(self):
          self.env.config.set('query', 'default_columns', 'id,time,changetime,summary,milestone,type')
          query = Query(self.env)