aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tools/pagination.py
diff options
context:
space:
mode:
authorAaron Williamson <aaron@copiesofcopies.org>2012-01-17 00:59:21 -0500
committerAaron Williamson <aaron@copiesofcopies.org>2012-01-17 00:59:21 -0500
commit99a270e95298b248a77b07203ab3921078bd7906 (patch)
tree34711abf27ab7a614c92842b456bf74ec3d5d5fb /mediagoblin/tools/pagination.py
parent25b48323a86a1036112f2f33c889d5d12d5dee9c (diff)
parent8c7701f9f1653cf4038143cfb7a497ae21edf108 (diff)
downloadmediagoblin-99a270e95298b248a77b07203ab3921078bd7906.tar.lz
mediagoblin-99a270e95298b248a77b07203ab3921078bd7906.tar.xz
mediagoblin-99a270e95298b248a77b07203ab3921078bd7906.zip
Merged changes with upstream
Diffstat (limited to 'mediagoblin/tools/pagination.py')
-rw-r--r--mediagoblin/tools/pagination.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/mediagoblin/tools/pagination.py b/mediagoblin/tools/pagination.py
index 3ea96e6d..5ebc3c5a 100644
--- a/mediagoblin/tools/pagination.py
+++ b/mediagoblin/tools/pagination.py
@@ -19,8 +19,10 @@ import copy
from math import ceil, floor
from itertools import izip, count
+
PAGINATION_DEFAULT_PER_PAGE = 30
+
class Pagination(object):
"""
Pagination class for mongodb queries.
@@ -37,9 +39,9 @@ class Pagination(object):
Args:
- page: requested page
- per_page: number of objects per page
- - cursor: db cursor
- - jump_to_id: ObjectId, sets the page to the page containing the object
- with _id == jump_to_id.
+ - cursor: db cursor
+ - jump_to_id: ObjectId, sets the page to the page containing the
+ object with _id == jump_to_id.
"""
self.page = page
self.per_page = per_page
@@ -51,7 +53,7 @@ class Pagination(object):
cursor = copy.copy(self.cursor)
for (doc, increment) in izip(cursor, count(0)):
- if doc['_id'] == jump_to_id:
+ if doc._id == jump_to_id:
self.page = 1 + int(floor(increment / self.per_page))
self.active_id = jump_to_id
@@ -91,19 +93,19 @@ class Pagination(object):
last = num
def get_page_url_explicit(self, base_url, get_params, page_no):
- """
+ """
Get a page url by adding a page= parameter to the base url
- """
+ """
new_get_params = copy.copy(get_params or {})
new_get_params['page'] = page_no
return "%s?%s" % (
base_url, urllib.urlencode(new_get_params))
def get_page_url(self, request, page_no):
- """
+ """
Get a new page url based of the request, and the new page number.
This is a nice wrapper around get_page_url_explicit()
- """
+ """
return self.get_page_url_explicit(
request.full_path, request.GET, page_no)