From 104b466e1e7b486cd990bfcac1b62a9672ddd73c Mon Sep 17 00:00:00 2001 From: Dalahro Date: Fri, 18 Nov 2016 11:31:33 +0100 Subject: [PATCH] Pagination sur le controle des factures --- cotisations/templates/cotisations/control.html | 3 +++ cotisations/views.py | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cotisations/templates/cotisations/control.html b/cotisations/templates/cotisations/control.html index 02c6ee41..b20e16db 100644 --- a/cotisations/templates/cotisations/control.html +++ b/cotisations/templates/cotisations/control.html @@ -6,6 +6,9 @@ {% block content %}

Controle et validité des factures

+{% if facture_list.paginator %} +{% include "pagination.html" with list=facture_list %} +{% endif %}
{% csrf_token %} {{ controlform.management_form }} diff --git a/cotisations/views.py b/cotisations/views.py index 6db859ca..aa9834c6 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -315,11 +315,20 @@ def del_banque(request): def control(request): facture_list = Facture.objects.order_by('date').reverse() controlform_set = modelformset_factory(Facture, fields=('control','valid'), extra=0) - controlform = controlform_set(request.POST or None, queryset=facture_list) + paginator = Paginator(facture_list, PAGINATION_NUMBER) + page = request.GET.get('page') + try: + facture_list = paginator.page(page) + except PageNotAnInteger: + facture_list = paginator.page(1) + except EmptyPage: + facture_list = paginator.page(paginator.num.pages) + page_query = Facture.objects.order_by('date').reverse().filter(id__in=[facture.id for facture in facture_list]) + controlform = controlform_set(request.POST or None, queryset=page_query) if controlform.is_valid(): controlform.save() return redirect("/cotisations/control/") - return render(request, 'cotisations/control.html', {'controlform': controlform}) + return render(request, 'cotisations/control.html', {'facture_list': facture_list, 'controlform': controlform}) @login_required @permission_required('cableur')