From 196bc96616affa8ce002d9d654e7358814cb6a64 Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Wed, 13 Dec 2023 19:40:33 +0100 Subject: [PATCH] feat: improve listview pagination This improves the pagination links below the table in the generic list view. to make the template code smaller, we introducce a templatetag `page_range` that uses the paginators get_elided_page_range to get a list of useful pagination links. Closes: #416 --- .../apis_metainfo/templates/generic_list.html | 125 +++++++----------- apis_core/core/templatetags/apiscore.py | 5 + 2 files changed, 52 insertions(+), 78 deletions(-) diff --git a/apis_core/apis_metainfo/templates/generic_list.html b/apis_core/apis_metainfo/templates/generic_list.html index 89cc3a2e0..aa8e65c57 100644 --- a/apis_core/apis_metainfo/templates/generic_list.html +++ b/apis_core/apis_metainfo/templates/generic_list.html @@ -5,6 +5,7 @@ {% load i18n %} {% load crispy_forms_field %} {% load crispy_forms_tags %} +{% load apiscore %} {% block title %}Browse {{ class_name }}{% endblock %} @@ -255,48 +256,59 @@

{{ data.title }}

{% block pagination.allpages %} -
- {% with table.page.object_list|length as count %}

Page total: {{ count }}

{% endwith %} -
- - {% endif %} - - {% endblock pagination.allpages %} + - {% if 'entities' in APPS %}{% endif %} diff --git a/apis_core/core/templatetags/apiscore.py b/apis_core/core/templatetags/apiscore.py index a171d68a5..e001c1a30 100644 --- a/apis_core/core/templatetags/apiscore.py +++ b/apis_core/core/templatetags/apiscore.py @@ -8,3 +8,8 @@ @register.simple_tag def shared_url(): return getattr(settings, "SHARED_URL", "/static/") + + +@register.simple_tag +def page_range(paginator, number): + return paginator.get_elided_page_range(number=number)