support ordering
authorjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 29 Jun 2009 10:55:42 +0000 (10:55 +0000)
committerjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 29 Jun 2009 10:55:42 +0000 (10:55 +0000)
git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@440 e071eeec-0327-468d-9b6a-08194a12b294

ldapdb/models/query.py

index 8890b53a4c0ec2dc67d441f192453e70606a0a4d..938abd5904aac6cf79230c134fd7b7f8d8958b04 100644 (file)
@@ -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):