Expose first and last page of pagination

Implements a *_first_page and *_last_page for all paginable objects.
These can be used fo jump to first and last pages.
This commit is contained in:
Joachim Lusiardi 2019-09-14 21:27:13 +02:00
commit 4e2e3b4a1b
2 changed files with 29 additions and 1 deletions

View file

@ -137,18 +137,24 @@ Variable Description
====================== =================================================== ====================== ===================================================
articles_paginator A paginator object for the list of articles articles_paginator A paginator object for the list of articles
articles_page The current page of articles articles_page The current page of articles
articles_first_page The first page of articles
articles_previous_page The previous page of articles (``None`` if page does articles_previous_page The previous page of articles (``None`` if page does
not exist) not exist)
articles_next_page The next page of articles (``None`` if page does articles_next_page The next page of articles (``None`` if page does
not exist) not exist)
articles_last_page The first page of articles
dates_paginator A paginator object for the article list, ordered by dates_paginator A paginator object for the article list, ordered by
date, ascending. date, ascending.
dates_page The current page of articles, ordered by date, dates_page The current page of articles, ordered by date,
ascending. ascending.
dates_first_page The first page of articles, ordered by date,
ascending.
dates_previous_page The previous page of articles, ordered by date, dates_previous_page The previous page of articles, ordered by date,
ascending (``None`` if page does not exist) ascending (``None`` if page does not exist)
dates_next_page The next page of articles, ordered by date, dates_next_page The next page of articles, ordered by date,
ascending (``None`` if page does not exist) ascending (``None`` if page does not exist)
dates_last_page The last page of articles, ordered by date,
ascending.
page_name 'index' -- useful for pagination links page_name 'index' -- useful for pagination links
====================== =================================================== ====================== ===================================================
@ -170,18 +176,24 @@ dates Articles by this author, but ordered by date,
ascending ascending
articles_paginator A paginator object for the list of articles articles_paginator A paginator object for the list of articles
articles_page The current page of articles articles_page The current page of articles
articles_first_page The first page of articles
articles_previous_page The previous page of articles (``None`` if page does articles_previous_page The previous page of articles (``None`` if page does
not exist) not exist)
articles_next_page The next page of articles (``None`` if page does articles_next_page The next page of articles (``None`` if page does
not exist) not exist)
articles_last_page The first page of articles
dates_paginator A paginator object for the article list, ordered by dates_paginator A paginator object for the article list, ordered by
date, ascending. date, ascending.
dates_page The current page of articles, ordered by date, dates_page The current page of articles, ordered by date,
ascending. ascending.
dates_first_page The first page of articles, ordered by date,
ascending.
dates_previous_page The previous page of articles, ordered by date, dates_previous_page The previous page of articles, ordered by date,
ascending (``None`` if page does not exist) ascending (``None`` if page does not exist)
dates_next_page The next page of articles, ordered by date, dates_next_page The next page of articles, ordered by date,
ascending (``None`` if page does not exist) ascending (``None`` if page does not exist)
dates_last_page The last page of articles, ordered by date,
ascending.
page_name AUTHOR_URL where everything after `{slug}` is page_name AUTHOR_URL where everything after `{slug}` is
removed -- useful for pagination links removed -- useful for pagination links
====================== =================================================== ====================== ===================================================
@ -204,18 +216,24 @@ dates Articles for this category, but ordered by date,
ascending ascending
articles_paginator A paginator object for the list of articles articles_paginator A paginator object for the list of articles
articles_page The current page of articles articles_page The current page of articles
articles_first_page The first page of articles
articles_previous_page The previous page of articles (``None`` if page does articles_previous_page The previous page of articles (``None`` if page does
not exist) not exist)
articles_next_page The next page of articles (``None`` if page does articles_next_page The next page of articles (``None`` if page does
not exist) not exist)
articles_last_page The first page of articles
dates_paginator A paginator object for the list of articles, dates_paginator A paginator object for the list of articles,
ordered by date, ascending ordered by date, ascending
dates_page The current page of articles, ordered by date, dates_page The current page of articles, ordered by date,
ascending ascending
dates_first_page The first page of articles, ordered by date,
ascending.
dates_previous_page The previous page of articles, ordered by date, dates_previous_page The previous page of articles, ordered by date,
ascending (``None`` if page does not exist) ascending (``None`` if page does not exist)
dates_next_page The next page of articles, ordered by date, dates_next_page The next page of articles, ordered by date,
ascending (``None`` if page does not exist) ascending (``None`` if page does not exist)
dates_last_page The last page of articles, ordered by date,
ascending.
page_name CATEGORY_URL where everything after `{slug}` is page_name CATEGORY_URL where everything after `{slug}` is
removed -- useful for pagination links removed -- useful for pagination links
====================== =================================================== ====================== ===================================================
@ -293,18 +311,24 @@ dates Articles related to this tag, but ordered by date,
ascending ascending
articles_paginator A paginator object for the list of articles articles_paginator A paginator object for the list of articles
articles_page The current page of articles articles_page The current page of articles
articles_first_page The first page of articles
articles_previous_page The previous page of articles (``None`` if page does articles_previous_page The previous page of articles (``None`` if page does
not exist) not exist)
articles_next_page The next page of articles (``None`` if page does articles_next_page The next page of articles (``None`` if page does
not exist) not exist)
articles_last_page The first page of articles
dates_paginator A paginator object for the list of articles, dates_paginator A paginator object for the list of articles,
ordered by date, ascending ordered by date, ascending
dates_page The current page of articles, ordered by date, dates_page The current page of articles, ordered by date,
ascending ascending
dates_first_page The first page of articles, ordered by date,
ascending.
dates_previous_page The previous page of articles, ordered by date, dates_previous_page The previous page of articles, ordered by date,
ascending (``None`` if page does not exist) ascending (``None`` if page does not exist)
dates_next_page The next page of articles, ordered by date, dates_next_page The next page of articles, ordered by date,
ascending (``None`` if page does not exist) ascending (``None`` if page does not exist)
dates_last_page The last page of articles, ordered by date,
ascending.
page_name TAG_URL where everything after `{slug}` is removed page_name TAG_URL where everything after `{slug}` is removed
-- useful for pagination links -- useful for pagination links
====================== =================================================== ====================== ===================================================

View file

@ -249,16 +249,20 @@ class Writer(object):
paginated_kwargs = kwargs.copy() paginated_kwargs = kwargs.copy()
for key in paginators.keys(): for key in paginators.keys():
paginator = paginators[key] paginator = paginators[key]
first_page = paginator.page(1)
previous_page = paginator.page(page_num) \ previous_page = paginator.page(page_num) \
if page_num > 0 else None if page_num > 0 else None
page = paginator.page(page_num + 1) page = paginator.page(page_num + 1)
next_page = paginator.page(page_num + 2) \ next_page = paginator.page(page_num + 2) \
if page_num + 1 < paginator.num_pages else None if page_num + 1 < paginator.num_pages else None
last_page = paginator.page(paginator.num_pages)
paginated_kwargs.update( paginated_kwargs.update(
{'%s_paginator' % key: paginator, {'%s_paginator' % key: paginator,
'%s_page' % key: page, '%s_page' % key: page,
'%s_first_page' % key: first_page,
'%s_previous_page' % key: previous_page, '%s_previous_page' % key: previous_page,
'%s_next_page' % key: next_page}) '%s_next_page' % key: next_page,
'%s_last_page' % key: last_page})
localcontext = _get_localcontext( localcontext = _get_localcontext(
context, page.save_as, paginated_kwargs, relative_urls) context, page.save_as, paginated_kwargs, relative_urls)