]> git.ozlabs.org Git - patchwork/commitdiff
views/order: Apply default ordering as secondary
authorJeremy Kerr <jk@ozlabs.org>
Wed, 12 Mar 2014 00:44:12 +0000 (08:44 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 21 Apr 2014 02:39:12 +0000 (10:39 +0800)
If we're ordering by a certain non-default field, then the ordering
of patches with that same field will be arbitrary.

This change applies the default as a secondary ordering, so we're not
left with an arbitrary sub-order.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
apps/patchwork/utils.py
apps/patchwork/views/__init__.py

index f8fee3fcaaa1c8d0db9e5d50b4989ac75ae9ef3c..37b85ce1f503396c3363d2ad3f59c70315471134 100644 (file)
@@ -93,11 +93,23 @@ class Order(object):
         else:
             return '-' + self.order
 
-    def query(self):
+    def apply(self, qs):
         q = self.order_map[self.order]
         if self.reversed:
             q = '-' + q
-        return q
+
+        qs = qs.order_by(q)
+
+        # if we're using a non-default order, add the default as a secondary
+        # ordering. We reverse the default if the primary is reversed.
+        (default_name, default_reverse) = self.default_order
+        if self.order != default_name:
+            q = self.order_map[default_name]
+            if self.reversed ^ default_reverse:
+                q = '-' + q
+            qs = qs.order_by(q)
+
+        return qs
 
 bundle_actions = ['create', 'add', 'remove']
 def set_bundle(user, project, action, data, patches, context):
index a823388a089171e2443540b61d2e2beb7c20fc0b..4c636182ed30fc82e3e927286776816934b85289 100644 (file)
@@ -106,7 +106,7 @@ def generic_list(request, project, view,
 
     patches = context.filters.apply(patches)
     if not editable_order:
-        patches = patches.order_by(order.query())
+        patches = order.apply(patches)
 
     paginator = Paginator(request, patches)