diff options
author | luxagraf <sng@luxagraf.net> | 2021-08-14 09:39:08 -0400 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2021-08-14 09:39:08 -0400 |
commit | 9327e01c60b114286f5a142552aae60843029a48 (patch) | |
tree | 7f353f4299d50013c3b90f7b749fc6ab211b32d4 /app/lib/pagination/middleware.py | |
parent | 0feb366b10cf422f12d18fa753e5d876120f4195 (diff) |
initial commit
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 + |