import urllib
from math import ceil
import copy
-import decorators
-from webob import exc
TESTS_ENABLED = False
def _activate_testing():
translations=this_gettext)
+PAGINATION_DEFAULT_PER_PAGE = 30
+
class Pagination(object):
"""
Pagination class for mongodb queries.
get actual data slice through __call__().
"""
- def __init__(self, page, cursor, per_page=2):
+ def __init__(self, page, cursor, per_page=PAGINATION_DEFAULT_PER_PAGE):
"""
Initializes Pagination
yield num
last = num
- def get_page_url(self, path_info, page_no, get_params=None):
+ def get_page_url_explicit(self, base_url, get_params, page_no):
"""
- Get a new page based of the path_info, the new page number,
- and existing get parameters.
+ 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" % (
- path_info, urllib.urlencode(new_get_params))
-
+ 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.path_info, request.GET, page_no)