From cf7aa4189386a4d4ffd8eb2cc80992fe1603f0c1 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Thu, 17 Dec 2020 12:27:38 -0800 Subject: channel: include first and last pages when sorting by new MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Last page as a substitute for sorting by oldest since sorting by oldest doesn't allow arbitrary page numbers Signed-off-by: Jesús --- youtube/templates/common_elements.html | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'youtube/templates/common_elements.html') diff --git a/youtube/templates/common_elements.html b/youtube/templates/common_elements.html index fcd4125..9ccafeb 100644 --- a/youtube/templates/common_elements.html +++ b/youtube/templates/common_elements.html @@ -66,7 +66,7 @@ {% endmacro %} -{% macro page_buttons(estimated_pages, url, parameters_dictionary) %} +{% macro page_buttons(estimated_pages, url, parameters_dictionary, include_ends=false) %} {% set current_page = parameters_dictionary.get('page', 1)|int %} {% set parameters_dictionary = parameters_dictionary.to_dict() %} {% if current_page is le(5) %} @@ -77,17 +77,26 @@ {% set page_end = [current_page + 4, estimated_pages]|min %} {% endif %} + {% if include_ends and page_start is gt(1) %} + {% set _ = parameters_dictionary.__setitem__('page', 1) %} + {{ 1 }} + {% endif %} + {% for page in range(page_start, page_end+1) %} {% if page == current_page %} {% else %} - {# IMPORTANT: Jinja SUCKS #} {# https://stackoverflow.com/questions/36886650/how-to-add-a-new-entry-into-a-dictionary-object-while-using-jinja2 #} {% set _ = parameters_dictionary.__setitem__('page', page) %} {{ page }} {% endif %} {% endfor %} + {% if include_ends and page_end is lt(estimated_pages) %} + {% set _ = parameters_dictionary.__setitem__('page', estimated_pages) %} + {{ estimated_pages }} + {% endif %} + {% endmacro %} {% macro next_previous_buttons(is_last_page, url, parameters_dictionary) %} -- cgit v1.2.3