Author: Alex
Date: 2010-06-21 14:14:13 -0500 (Mon, 21 Jun 2010)
New Revision: 13371

Modified:
   django/branches/soc2010/query-refactor/django/contrib/mongodb/compiler.py
   django/branches/soc2010/query-refactor/tests/regressiontests/mongodb/tests.py
Log:
[soc2010/query-refactor] Implemented slicing, also found a bug in 
MongoDB/PyMongo.

Modified: 
django/branches/soc2010/query-refactor/django/contrib/mongodb/compiler.py
===================================================================
--- django/branches/soc2010/query-refactor/django/contrib/mongodb/compiler.py   
2010-06-21 18:38:24 UTC (rev 13370)
+++ django/branches/soc2010/query-refactor/django/contrib/mongodb/compiler.py   
2010-06-21 19:14:13 UTC (rev 13371)
@@ -63,7 +63,6 @@
         assert not self.query.distinct
         assert not self.query.extra
         assert not self.query.having
-        assert self.query.high_mark is None
         
         filters = self.get_filters(self.query.where)
         cursor = 
self.connection.db[self.query.model._meta.db_table].find(filters)
@@ -72,6 +71,10 @@
                 (ordering.lstrip("-"), DESCENDING if ordering.startswith("-") 
else ASCENDING)
                 for ordering in self.query.order_by
             ])
+        if self.query.low_mark:
+            cursor = cursor.skip(self.query.low_mark)
+        if self.query.high_mark is not None:
+            cursor = cursor.limit(self.query.high_mark - self.query.low_mark)
         return cursor
     
     def results_iter(self):

Modified: 
django/branches/soc2010/query-refactor/tests/regressiontests/mongodb/tests.py
===================================================================
--- 
django/branches/soc2010/query-refactor/tests/regressiontests/mongodb/tests.py   
    2010-06-21 18:38:24 UTC (rev 13370)
+++ 
django/branches/soc2010/query-refactor/tests/regressiontests/mongodb/tests.py   
    2010-06-21 19:14:13 UTC (rev 13371)
@@ -85,8 +85,35 @@
             ],
             lambda g: g.name,
         )
+    
+    def test_slicing(self):
+        artists = [
+            Artist.objects.create(name="Huey Lewis"),
+            Artist.objects.create(name="John Hiatt"),
+            Artist.objects.create(name="Jackson Browne"),
+            Artist.objects.create(name="Rick Springfield"),
+        ]
         
-    
+        for i in xrange(5):
+            # TODO: should be i, but Mongo falls over with limit(0)
+            for j in xrange(i+1, 5):
+                self.assertQuerysetEqual(
+                    Artist.objects.all()[i:j],
+                    artists[i:j],
+                    lambda a: a,
+                )
+        self.assertQuerysetEqual(
+            Artist.objects.all()[:3],
+            artists[:3],
+            lambda a: a,
+        )
+        
+        self.assertQuerysetEqual(
+            Artist.objects.all()[2:],
+            artists[2:],
+            lambda a: a,
+        )
+
     def test_not_equals(self):
         q = Group.objects.create(name="Queen", year_formed=1971)
         e = Group.objects.create(name="The E Street Band", year_formed=1972)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to