Paging long lists¶
The howtos.pagerbootstrap example lets a user page though a very long list of Addresses, displaying only a managable number at a time.
Three objects play a role in this scenario:
A
SequentialPageIndexbreaks the long list of Addresses into separate chunks.AddressList is a
PagedPanel-–it displays the appropriate chunk of Addresses (itscurrent_contents()).An accompanying
PageMenuallows the user to navigate.
class AddressBookPanel(Div):
def __init__(self, view):
super().__init__(view)
self.add_child(H(view, 1, text='Addresses'))
self.page_index = SequentialPageIndex(Address.all_addresses(), items_per_page=5)
self.address_list = AddressList(view, self.page_index)
self.page_menu = PageMenu(view, 'page_menu', self.page_index, self.address_list)
self.add_children([self.page_menu, self.address_list])
Since AddressList is a PagedPanel, it automatically refreshes and
computes its current_contents based on the given
SequentialPageIndex.
class AddressList(PagedPanel):
def __init__(self, view, page_index):
super().__init__(view, page_index, 'addresslist')
for address in self.current_contents:
self.add_child(P(view, text='%s: %s' % (address.name, address.email_address)))
Other implementations of PageIndex are possible, such as
AnnualPageIndex which arranges all items with the same year
together.
