summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2014-03-12 08:44:12 +0800
committerJeremy Kerr <jk@ozlabs.org>2014-04-21 10:39:12 +0800
commitf24310486bb97291350fa84f1e895635facb4155 (patch)
tree02701b328d468ff795b4ccc60adbdf3be6d8a3ac /apps
parent26d551a1ee9e888c1656730c19414003124a4ec7 (diff)
downloadpatchwork-f24310486bb97291350fa84f1e895635facb4155.tar.bz2
patchwork-f24310486bb97291350fa84f1e895635facb4155.tar.xz
views/order: Apply default ordering as secondary
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>
Diffstat (limited to 'apps')
-rw-r--r--apps/patchwork/utils.py16
-rw-r--r--apps/patchwork/views/__init__.py2
2 files changed, 15 insertions, 3 deletions
diff --git a/apps/patchwork/utils.py b/apps/patchwork/utils.py
index f8fee3f..37b85ce 100644
--- a/apps/patchwork/utils.py
+++ b/apps/patchwork/utils.py
@@ -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):
diff --git a/apps/patchwork/views/__init__.py b/apps/patchwork/views/__init__.py
index a823388..4c63618 100644
--- a/apps/patchwork/views/__init__.py
+++ b/apps/patchwork/views/__init__.py
@@ -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)