class trustar.models.numbered_page.NumberedPage(items=None, page_number=None, page_size=None, total_elements=None, has_next=None)

This class models a page of items that would be found in the body of a response from an endpoint that uses number- based pagination. Not all paginated endpoints will use page_number. For instance, the get_reports_page method requires pagination to be performed by continuously adjusting the from and to parameters.

  • items – The list of items of the page; i.e. a list of indicators, reports, etc.
  • page_number – The number of the page out of all total pages, indexed from 0. i.e. if there are 4 total pages of size 25, then page 0 will contain the first 25 elements, page 1 will contain the next 25, etc.
  • page_size – The size of the page that was request. Note that, if this is the last page, then this might not equal len(items). For instance, if pages of size 25 were requested, there are 107 total elements, and this is the last page, then page_size will be 25 even though the page only contains 7 elements.
  • total_elements – The total number of elements on the server, e.g. the total number of elements across all pages. Note that it is possible for this value to change between pages, since data can change between queries.
static from_dict(page, content_type=None)

Create a NumberedPage object from a dictionary. This method is intended for internal use, to construct a NumberedPage object from the body of a response json from a paginated endpoint.

  • page – The dictionary.
  • content_type – The class that the contents should be deserialized into.

The resulting NumberedPage object.

static get_page_generator(func, start_page=0, page_size=None)

Constructs a generator for retrieving pages from a paginated endpoint. This method is intended for internal use.

  • func – Should take parameters page_number and page_size and return the corresponding NumberedPage object.
  • start_page – The page to start on.
  • page_size – The size of each page.

A generator that generates each successive page.

Returns:The total number of pages on the server.
Returns:True if there are more pages available on the server.

Creates a dictionary representation of the page.

Parameters:remove_nones – Whether None values should be filtered out of the dictionary. Defaults to False.
Returns:A dictionary representation of the page.