diff options
Diffstat (limited to 'app/lib/pagination/middleware.py')
-rw-r--r-- | app/lib/pagination/middleware.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/app/lib/pagination/middleware.py b/app/lib/pagination/middleware.py new file mode 100644 index 0000000..cf9f9cb --- /dev/null +++ b/app/lib/pagination/middleware.py @@ -0,0 +1,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 + |