hubgrep.lib.pagination module

Create pagination objects (PageLink) used in templating.

Bases: tuple

property class_name

Alias for field number 2

property label

Alias for field number 1

property url

Alias for field number 0

Constructs a list of PageLinks (namedtuple) for use in templating.

This list (when able & enabled) will contain a “previous” link at first index and a “next” link as the last item. It may also contain empty links as dividers when there are more pages total than shown.

The constructed list will look like below (“..” = divider links): [<previous>, <detach_left enum links>, .., <mid_start -enum links- mid_end>, .., <detach_right enum links>, <next>]

Detached links on left and right will only exist when the ends of the list are further away than what the enumerated links in the middle can show (enumerated_link_max). Like so, if current page is nr 12: 1 2 .. 10 11 12 13 14 15 .. 59 60

  • url – current url to modify and/or add query params on regarding pagination

  • offset – starting offset for the new url in terms of items shown

  • per_page – amount of results shown on the new page

  • results_total – total maximum for pagination to work within

  • enumerated_link_max – upper cap for amount of enumerated page-links (but not a cap for the returned list when “has_next_prev” is enabled)

  • detach_min – no link dividers for total links under this value

  • has_next_prev – sets label & url for links to adjacent pages (not counted toward link_max), if False it will still include empty PageLinks!

  • side_link_portions – decimal between 0 - 0.5 assigned to each static end of pagination link-sections