Commits

Odd Simon Simonsen committed 87edd16

Fixes for `default_order` and `default_group` patches. Mostly simplifications.

  • Participants
  • Parent commits 95ec5f2

Comments (0)

Files changed (2)

File default_group.diff

 # HG changeset patch
-# Parent ce28d2a2adf3bac5633a8e4ab66a107b29a98e81
+# Parent 51c05f4f7418051ab610b2b6c1538cfb901de235
 
-diff -r ce28d2a2adf3 trac/ticket/query.py
---- a/trac/ticket/query.py	Sun Dec 18 14:36:43 2011 +0100
-+++ b/trac/ticket/query.py	Sun Dec 18 14:37:14 2011 +0100
-@@ -141,8 +141,19 @@
-             if not is_valid_order(self.order):
-                 (self.order, self.desc) = ('priority', 0)
+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)
  
 -        if self.group not in field_names:
 -            self.group = None
-+        # Handle empty string as a request to not group the result
-+        if self.group != '' and self.group not in field_names:
-+            default_group = QueryModule(self.env).default_group
++        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, self.groupdesc) = (default_group, 0)
-+            
-+            if self.group not in field_names:
-+                (self.group, self.groupdesc) = (None, 0)
++                    self.group = default_group
  
          constraint_cols = {}
          for clause in self.constraints:
-@@ -423,7 +434,7 @@
+@@ -416,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,
-@@ -866,6 +877,10 @@
+@@ -859,6 +866,10 @@
      default_order = Option('query', 'default_order',
          default='priority',
          doc="""The default order to use for queries. (''since 0.13'')""")
  
      # IContentConverter methods
  
-diff -r ce28d2a2adf3 trac/ticket/tests/query.py
---- a/trac/ticket/tests/query.py	Sun Dec 18 14:36:43 2011 +0100
-+++ b/trac/ticket/tests/query.py	Sun Dec 18 14:37:14 2011 +0100
+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 @@
  ORDER BY COALESCE(t.id,0)=0,t.id""")
          self.assertEqual(['anonymous'], args)

File default_order.diff

 # HG changeset patch
-# Parent 35a2233089d56d6e771a0a0b6c4f354d25115898
+# Parent efb2b2e7af2b9204c99c084dfea6f37a7afde089
 
-diff -r 35a2233089d5 trac/ticket/query.py
---- a/trac/ticket/query.py	Sun Dec 18 00:04:34 2011 +0100
-+++ b/trac/ticket/query.py	Sun Dec 18 14:34:56 2011 +0100
-@@ -125,8 +125,21 @@
-         self.cols = [c for c in cols or [] if c in field_names or 
+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 @@
                       c == 'id']
          self.rows = [c for c in rows if c in field_names]
--        if self.order != 'id' and self.order not in field_names:
+         if self.order != 'id' and self.order not in field_names:
 -            self.order = 'priority'
-+
-+        def is_valid_order(order):
-+            return order == 'id' or order in field_names
-+        if not is_valid_order(self.order):
-+            default_order = QueryModule(self.env).default_order
-+            if default_order:
-+                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, 0)
-+            
-+            if not is_valid_order(self.order):
-+                (self.order, self.desc) = ('priority', 0)
++            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)
  
          if self.group not in field_names:
              self.group = None
-@@ -849,6 +862,10 @@
+@@ -849,6 +855,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'')""")
  
      # IContentConverter methods
  
-diff -r 35a2233089d5 trac/ticket/tests/query.py
---- a/trac/ticket/tests/query.py	Sun Dec 18 00:04:34 2011 +0100
-+++ b/trac/ticket/tests/query.py	Sun Dec 18 14:34:56 2011 +0100
-@@ -101,7 +101,7 @@
-         tickets = query.execute(self.req)
- 
-     def test_all_ordered_by_priority_desc(self):
--        query = Query(self.env, desc=1) # priority is default order
-+        query = Query(self.env, order='priority', desc=1)
-         sql, args = query.get_sql()
-         self.assertEqualSQL(sql,
- """SELECT t.id AS id,t.summary AS summary,t.owner AS owner,t.type AS type,t.status AS status,t.priority AS priority,t.milestone AS milestone,t.time AS time,t.changetime AS changetime,priority.value AS priority_value
+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 @@
          self.assertEqual(['anonymous'], args)
          tickets = query.execute(self.req)