From 5a80e0dc0886927f14b00ccf329fa4ec6d36ffa5 Mon Sep 17 00:00:00 2001 From: jlaine Date: Mon, 29 Jun 2009 10:55:42 +0000 Subject: [PATCH] support ordering git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@440 e071eeec-0327-468d-9b6a-08194a12b294 --- ldapdb/models/query.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ldapdb/models/query.py b/ldapdb/models/query.py index 8890b53..938abd5 100644 --- a/ldapdb/models/query.py +++ b/ldapdb/models/query.py @@ -61,6 +61,22 @@ class Query(BaseQuery): except: raise self.model.DoesNotExist + # perform sorting + if self.extra_order_by: + ordering = self.extra_order_by + elif not self.default_ordering: + ordering = self.order_by + else: + ordering = self.order_by or self.model._meta.ordering + def getkey(x): + keys = [] + for k in ordering: + attr = self.model._meta.get_field(k).db_column + keys.append(x[1][attr]) + return keys + vals = sorted(vals, key=lambda x: getkey(x)) + + # process results for dn, attrs in vals: row = [dn] for field in iter(self.model._meta.fields): -- 2.30.2