From 274a7b7137cc08f48d867a44f3169c0896acca31 Mon Sep 17 00:00:00 2001 From: Bartuccio Antoine Date: Thu, 28 Nov 2019 01:15:57 +0100 Subject: [PATCH] core/club: allow adding custom js action to pagination link, useful for FormDetailView with pagination --- club/templates/club/club_sellings.jinja | 13 ++++++++++--- club/views.py | 3 ++- core/templates/core/macros.jinja | 9 +++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/club/templates/club/club_sellings.jinja b/club/templates/club/club_sellings.jinja index 1062f8cb..6759fb3d 100644 --- a/club/templates/club/club_sellings.jinja +++ b/club/templates/club/club_sellings.jinja @@ -3,7 +3,7 @@ {% block content %}

{% trans %}Sellings{% endtrans %}

-
+ {% csrf_token %} {{ form }}

@@ -28,7 +28,7 @@ - {% for s in result %} + {% for s in paginated_result %} {{ s.date|localtime|date(DATETIME_FORMAT) }} {{ s.date|localtime|time(DATETIME_FORMAT) }} {{ s.counter }} @@ -53,7 +53,14 @@ {% endfor %} -{{ paginate(result, paginator) }} + +{{ paginate(paginated_result, paginator, "formPagination(this)") }} {% endblock %} diff --git a/club/views.py b/club/views.py index d90d51bf..cf7cab01 100644 --- a/club/views.py +++ b/club/views.py @@ -354,6 +354,7 @@ class ClubSellingView(ClubTabsMixin, CanEditMixin, DetailFormView): qs = Selling.objects.filter(club=self.object) kwargs["result"] = qs[:0] + kwargs["paginated_result"] = kwargs["result"] kwargs["total"] = 0 kwargs["total_quantity"] = 0 kwargs["benefit"] = 0 @@ -392,7 +393,7 @@ class ClubSellingView(ClubTabsMixin, CanEditMixin, DetailFormView): kwargs["paginator"] = Paginator(kwargs["result"], self.paginate_by) try: - kwargs["result"] = kwargs["paginator"].page(self.asked_page) + kwargs["paginated_result"] = kwargs["paginator"].page(self.asked_page) except InvalidPage: raise Http404 diff --git a/core/templates/core/macros.jinja b/core/templates/core/macros.jinja index d9dd68c2..965c6f11 100644 --- a/core/templates/core/macros.jinja +++ b/core/templates/core/macros.jinja @@ -113,10 +113,11 @@ {% endif %} {% endmacro %} -{% macro paginate(page_obj, paginator) %} +{% macro paginate(page_obj, paginator, js_action) %} + {% set js = js_action|default('') %} {% if page_obj.has_previous() or page_obj.has_next() %} {% if page_obj.has_previous() %} - {% trans %}Previous{% endtrans %} + {% trans %}Previous{% endtrans %} {% else %} {% trans %}Previous{% endtrans %} {% endif %} @@ -124,11 +125,11 @@ {% if page_obj.number == i %} {{ i }} ({% trans %}current{% endtrans %}) {% else %} - {{ i }} + {{ i }} {% endif %} {% endfor %} {% if page_obj.has_next() %} - {% trans %}Next{% endtrans %} + {% trans %}Next{% endtrans %} {% else %} {% trans %}Next{% endtrans %} {% endif %}