From: Jeremy Kerr Date: Wed, 12 Mar 2014 00:44:12 +0000 (+0800) Subject: views/order: Apply default ordering as secondary X-Git-Url: https://git.ozlabs.org/?a=commitdiff_plain;h=f24310486bb97291350fa84f1e895635facb4155;p=patchwork 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 --- 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)