mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 05:59:44 -04:00
Move pagination utils into own module
This continues the pattern established in [1], just to chip away a bit more at the random collection of stuff in utils/__init__.py. [1]: https://github.com/alphagov/notifications-admin/pull/3923
This commit is contained in:
27
app/utils/pagination.py
Normal file
27
app/utils/pagination.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from flask import request, url_for
|
||||
|
||||
|
||||
def get_page_from_request():
|
||||
if 'page' in request.args:
|
||||
try:
|
||||
return int(request.args['page'])
|
||||
except ValueError:
|
||||
return None
|
||||
else:
|
||||
return 1
|
||||
|
||||
|
||||
def generate_previous_dict(view, service_id, page, url_args=None):
|
||||
return generate_previous_next_dict(view, service_id, page - 1, 'Previous page', url_args or {})
|
||||
|
||||
|
||||
def generate_next_dict(view, service_id, page, url_args=None):
|
||||
return generate_previous_next_dict(view, service_id, page + 1, 'Next page', url_args or {})
|
||||
|
||||
|
||||
def generate_previous_next_dict(view, service_id, page, title, url_args):
|
||||
return {
|
||||
'url': url_for(view, service_id=service_id, page=page, **url_args),
|
||||
'title': title,
|
||||
'label': 'page {}'.format(page)
|
||||
}
|
||||
Reference in New Issue
Block a user