blob: cf9f9cb5f7deac1701d913692103c72f4f1e07ed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
class PaginationMiddleware(object):
"""
Inserts a variable representing the current page onto the request object if
it exists in either **GET** or **POST** portions of the request.
"""
def process_request(self, request):
try:
request.page = int(request.REQUEST['page'])
except (KeyError, ValueError):
request.page = 1
def process_view(self, request, view_func, view_args, view_kwargs):
if 'paginate' in view_kwargs:
del view_kwargs['paginate']
if 'page_url' in view_kwargs:
request.page_url = view_kwargs['page_url']
del view_kwargs['page_url']
if 'page' in view_kwargs:
request.page = int(view_kwargs['page'])
del view_kwargs['page']
else:
request.page = 1
|