From 5c09151c89874509fb697c842aea143b378afcc6 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Fri, 24 Jul 2015 17:19:03 -0300 Subject: [PATCH] Add docs to pagination function in crud --- sapl/crud.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sapl/crud.py b/sapl/crud.py index f357ba780..aaa037a7c 100644 --- a/sapl/crud.py +++ b/sapl/crud.py @@ -15,6 +15,15 @@ def from_to(start, end): def make_pagination(index, num_pages): + '''Make a list of adjacent page ranges interspersed with "None"s + + The list starts with [1, 2] and end with [num_pages-1, num_pages]. + The list includes [index-1, index, index+1] + "None"s separate those ranges and mean ellipsis (...) + + Example: [1, 2, None, 10, 11, 12, None, 29, 30] + ''' + PAGINATION_LENGTH = 10 if num_pages <= PAGINATION_LENGTH: return from_to(1, num_pages) @@ -110,8 +119,6 @@ def build_crud(model, *layout): context_data = super(CrudListView, self).get_context_data(**kwargs) paginator = context_data['paginator'] current_page = context_data['page_obj'] - # TODO set custom_page_range to something like - # [1, 2, None, 10, 11, 12, None, 29, 30] context_data['custom_page_range'] = make_pagination( current_page.number, paginator.num_pages) return context_data