mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-14 17:22:17 -05:00
accepts a page parameter to control what page of data returns additional pagination fields in the response dict * page_size: will always be 50. defined by Config.PAGE_SIZE * total: the total amount of unpaginated records * links: dict containing optionally prev, next, and last, links to other relevant pagination pages also cleaned up some test imports
14 lines
459 B
Python
14 lines
459 B
Python
from flask import url_for
|
|
|
|
|
|
def pagination_links(pagination, endpoint, **kwargs):
|
|
if 'page' in kwargs:
|
|
kwargs.pop('page', None)
|
|
links = {}
|
|
if pagination.has_prev:
|
|
links['prev'] = url_for(endpoint, page=pagination.prev_num, **kwargs)
|
|
if pagination.has_next:
|
|
links['next'] = url_for(endpoint, page=pagination.next_num, **kwargs)
|
|
links['last'] = url_for(endpoint, page=pagination.pages, **kwargs)
|
|
return links
|