Remove Mongoism query.skip()
authorSebastian Spaeth <Sebastian@SSpaeth.de>
Mon, 17 Dec 2012 11:56:29 +0000 (12:56 +0100)
committerSebastian Spaeth <Sebastian@SSpaeth.de>
Fri, 21 Dec 2012 10:30:29 +0000 (11:30 +0100)
sqlalchemy supports slice() or [n:m] just fine.

Right now, it seems we cannot distinguish beween "empty" results
and out-of bound slices. It would be nice if we could distinguish
these somehow.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
mediagoblin/db/sql/base.py
mediagoblin/tools/pagination.py

index 8aa9cc3abd5105468f3a49c8310b2070dd77abdf..fbbac6f919c750d5e387cc59494830cbd6e6ebab 100644 (file)
@@ -35,9 +35,6 @@ class GMGQuery(Query):
             key_col = desc(key_col)
         return self.order_by(key_col)
 
-    def skip(self, amount):
-        return self.offset(amount)
-
 
 Session = scoped_session(sessionmaker(query_cls=GMGQuery))
 
index 141d91cc0e2eb0b8bea3c42c417c269fa23c531d..af889abd7e60004244c0d2655007cb45bc1fe2ad 100644 (file)
@@ -63,8 +63,11 @@ class Pagination(object):
         """
         Returns slice of objects for the requested page
         """
-        return self.cursor.skip(
-            (self.page - 1) * self.per_page).limit(self.per_page)
+        # TODO, return None for out of index so templates can
+        # distinguish between empty galleries and out-of-bound pages???
+        return self.cursor.slice(
+            (self.page - 1) * self.per_page,
+            self.page * self.per_page)
 
     @property
     def pages(self):