fix slice handling
authorjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 31 May 2010 20:12:06 +0000 (20:12 +0000)
committerjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 31 May 2010 20:12:06 +0000 (20:12 +0000)
git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@913 e071eeec-0327-468d-9b6a-08194a12b294

examples/tests.py
ldapdb/models/query.py

index e96ad90..f99ea2e 100644 (file)
@@ -133,6 +133,30 @@ class GroupTestCase(BaseTestCase):
         qs = LdapGroup.objects.all()
         self.assertEquals(len(qs), 0)
 
+    def test_slice(self):
+        qs = LdapGroup.objects.all()
+        objs = list(qs)
+        self.assertEquals(len(objs), 3)
+        self.assertEquals(objs[0].gid, 1000)
+        self.assertEquals(objs[1].gid, 1001)
+        self.assertEquals(objs[2].gid, 1002)
+
+        qs = LdapGroup.objects.all()
+        objs = qs[:2]
+        for o in objs:
+            return 
+        print objs
+        self.assertEquals(len(objs), 2)
+        self.assertEquals(objs[0].gid, 1000)
+        self.assertEquals(objs[1].gid, 1001)
+        return
+
+        qs = LdapGroup.objects.all()
+        objs = qs[1:]
+        self.assertEquals(len(objs), 2)
+        self.assertEquals(objs[0].gid, 1001)
+        self.assertEquals(objs[1].gid, 1002)
+
     def test_update(self):
         g = LdapGroup.objects.get(name='foogroup')
 
index 8999c17..e422630 100644 (file)
@@ -113,7 +113,15 @@ class Compiler(object):
         vals = sorted(vals, cmp=cmpvals)
 
         # process results
+        pos = 0
         for dn, attrs in vals:
+            # FIXME : This is not optimal, we retrieve more results than we need
+            # but there is probably no other options as we can't perform ordering
+            #┬áserver side.
+            if (self.query.low_mark and pos < self.query.low_mark) or \
+               (self.query.high_mark is not None and pos >= self.query.high_mark):
+                pos += 1
+                continue
             row = []
             for field in iter(query.model._meta.fields):
                 if field.attname == 'dn':
@@ -123,6 +131,7 @@ class Compiler(object):
                 else:
                     row.append(None)
             yield row
+            pos += 1
 
 
 class WhereNode(BaseWhereNode):