vantage6.backend.common.resource.pagination.Pagination¶
- class Pagination(items, page, page_size, total, request)¶
Bases:
object
Class that handles pagination of a query.
- Parameters:
items (list[DeclarativeMeta]) – List of database resources to paginate
page (int) – Current page number
page_size (int) – Number of items per page
total (int) – Total number of items
request (flask.Request) – Request object
- Variables:
page (Page) – Page object
request (flask.Request) – Request object
- __init__(items, page, page_size, total, request)¶
Methods
__init__
(items, page, page_size, total, request)from_query
(query, request, resource_model[, ...])Create a Pagination object from a query.
Attributes
Set the headers for the response.
Puts links to other pages in the response header.
Construct links to other pages.
- classmethod from_query(query, request, resource_model, paginate=True)¶
Create a Pagination object from a query.
- Parameters:
query (sqlalchemy.orm.query) – Query to paginate
request (flask.Request) – Request object
resource_model (DeclarativeMeta) – SQLAlchemy model of the resource whose endpoint is being called
paginate (bool) – Whether to paginate the query or not, default True
- Returns:
Pagination object
- Return type:
- property headers: dict¶
Set the headers for the response.
- Returns:
Response headers
- Return type:
dict
- property link_header: str¶
Puts links to other pages in the response header.
- Returns:
Link header
- Return type:
str
- property metadata_links: dict¶
Construct links to other pages.
- Returns:
Links to other pages
- Return type:
dict