Package reahl.web.bootstrap.pagination

New in version 3.2.

Sometimes you need to display a long list of items. Displaying such a list on a single page is not a good idea, because the page will take forever to load.

This module provides a few classes you can use to build a single View that displays only one “pageful” of the list. You can then also include a PageMenu – a menu on which a user can choose to navigate to another section (or page) of the list.

' Copyright 2017, 2018, 2022 Reahl Software Services (Pty) Ltd. All rights reserved.

@startuml
!include ../../../../base.iuml

title Pagination

class "<b>Menu</b>" as Menu
class "<b>PageMenu</b>" as PageMenu{
	query_fields
}
note top: page number selector

class "<b>PagedPanel</b>" as PagedPanel{
	query_fields
}
note right: current page contents \nbeing displayed

class "<b>PageIndex</b>" as PageIndex{
	current_page_number
	start_page_number
}
note left of PageIndex : does all the calculations \nneeded by the \nparticipating Widgets
Widget <|--- PageMenu
Widget <|--- PagedPanel

PageMenu -right- PagedPanel : pagedPanel >
PageMenu -left- Menu : html_representation >
PageMenu -- PageIndex
PageIndex -- PagedPanel
PageIndex -right- Page
PageIndex <|-- AnnualPageIndex
PageIndex <|-- SequentialPageIndex

@enduml

PagedPanel

class reahl.web.bootstrap.pagination.PagedPanel(view, page_index, css_id)

A Div whose contents change, depending on the page selected by a user from a PageMenu. A programmer should subclass from PagedPanel, supplying an __init__ method which populates the PagedPanel with appropriate contents, based on its .current_contents.

Styling

Represented in HTML by an <div> element.

Parameters:
query_fields

Used to declare the arguments of this Widget on its class.

Override this class attribute to declare arguments this Widget, each described by a Field.

When constructed, the Widget uses the names and validation details of each Field to parse values for its arguments from the current query string. The resultant argument values are set as attributes on this Widget (with names matching the argument names).

To declare arguments on your own Widget class, assign a ExposedNames instance to query_fields and then assign a single-argument callable for each Widget argument to it. This callable will be called with the Widget instance as argument, and should return a Field describing it:

class MyWidget(Widget):
    query_fields = ExposedNames()
    query_fields.my_argument = lambda i: Field()

Changed in version 6.1: This used to be set up using a method using an exposed decorator.

property current_contents

The list of items that should be displayed for the current page.

PageIndex

class reahl.web.bootstrap.pagination.PageIndex(current_page_number=1, start_page_number=1, max_page_links=5)

An object responsible for breaking a long list of items up into shorter lists for display. Each such shorter list is referred to as a page. Different ways of breaking long lists into smaller lists are provided by subclasses.

Parameters:
  • current_page_number – The initial page shown to users.

  • start_page_number – The first page that should be listed in the current PageMenu.

  • max_page_links – The number of pages to be shown in the current PageMenu.

abstract get_contents_for_page(page_number)

Override this method in subclasses to obtain the correct list of items for the given page_number.

abstract property total_number_of_pages

Override this @property in subclasses to state what the total number of pages is.

SequentialPageIndex

class reahl.web.bootstrap.pagination.SequentialPageIndex(items, items_per_page=5, current_page_number=1, start_page_number=1, max_page_links=4)

A PageIndex that breaks a list of items up into smaller lists, by cutting the original list into sections that have a maximum number of items per page.

Parameters:
  • items – The long list of items.

  • items_per_page – The maximum number of items to allow on a page.

  • current_page_number – (See PageIndex)

  • start_page_number – (See PageIndex)

  • max_page_links – (See PageIndex)

get_contents_for_page(page_number)

Override this method in subclasses to obtain the correct list of items for the given page_number.

property total_number_of_pages

Override this @property in subclasses to state what the total number of pages is.

AnnualPageIndex

class reahl.web.bootstrap.pagination.AnnualPageIndex(annual_item_organiser, current_page_number=1, start_page_number=1, max_page_links=4)

A PageIndex that breaks a list of items up into smaller lists, by arranging all items that have the same year on the same page.

Parameters:
  • annual_item_organiser – An object that implements AnnualItemOrganiserProtocol. Its methods will be called to find the relevent items, or determine what years are applicable.

  • current_page_number – (See PageIndex)

  • start_page_number – (See PageIndex)

  • max_page_links – (See PageIndex)

get_contents_for_page(page_number)

Override this method in subclasses to obtain the correct list of items for the given page_number.

property total_number_of_pages

Override this @property in subclasses to state what the total number of pages is.