granicus_archiver.web.pagination

class granicus_archiver.web.pagination.Paginator(request: web.Request, items: Sequence[ItemT], total_items: int | None = None, current_index: int | None = None, per_page: int = 10, page_query_param: str = 'page', per_page_query_param: str = 'per_page', disable_pagination: bool = False)[source]

Bases: Generic

Helper class for paginating a sequence of items

Parameters:
  • request (Request)

  • items (Sequence)

  • total_items (int)

  • current_index (int)

  • per_page (int)

  • page_query_param (str)

  • per_page_query_param (str)

  • disable_pagination (bool)

request: Request

The request object

items: Sequence

The items to paginate

current_index: int

The current page index

total_items: int

The total number of items

per_page: int

The number of items per page

page_query_param: str

The query parameter for the page number

per_page_query_param: str

The query parameter for the number of items per page

pages: list[Page]

A list of Page objects

property num_pages: int

Number of pages

property current_page: Page[ItemT]

The current Page object

property paginating: bool

Flag to indicate whether pagination is active

iter_pages(max_pages: int = 10) Iterable[Page[ItemT]][source]

Iterate over pages

Iteration will be centered around the current page index within the given max_pages.

Parameters:

max_pages (int) – The maximum number of pages to iterate over

Return type:

Iterable[Page[ItemT]]

class granicus_archiver.web.pagination.Page(paginator: Paginator[ItemT], page_num: int)[source]

Bases: Generic

A page of items within a Paginator

Parameters:
page_num: int

The page number

property active: bool

Whether this page is the current_page

property start_index: int

The index of the first item within items for this page

property end_index: int

The index of the last item within items for this page

property has_next: bool

Whether there is a next page

property has_prev: bool

Whether there is a previous page

property prev_page_num: int

The index of the previous page

property next_page_num: int

The index of the next page

property next_page: Page[ItemT]

The next Page

property prev_page: Page[ItemT]

The previous Page

property url: URL

The URL for this page

property slice: slice

A slice object for the items of this page

property length: int

The number of items on this page