From 6d5a7267c1766a9a371e61501923e905230fc790 Mon Sep 17 00:00:00 2001 From: Thibault de BOUTRAY Date: Tue, 1 Nov 2016 16:32:14 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20en=20place=20de=20la=20pagination=20sur?= =?UTF-8?q?=20la=20liste=20des=20bannissements,=20et=20classement=20par=20?= =?UTF-8?q?ordre=20de=20date=20d=C3=A9croissante?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- users/templates/users/aff_bans.html | 4 ++++ users/views.py | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/users/templates/users/aff_bans.html b/users/templates/users/aff_bans.html index e4b410f9..3ebbf2db 100644 --- a/users/templates/users/aff_bans.html +++ b/users/templates/users/aff_bans.html @@ -1,3 +1,7 @@ +{% if ban_list.paginator %} +{% include "pagination.html" with list=ban_list %} +{% endif %} + diff --git a/users/views.py b/users/views.py index 8983a60f..d8b23d1c 100644 --- a/users/views.py +++ b/users/views.py @@ -402,7 +402,17 @@ def index(request): @login_required @permission_required('cableur') def index_ban(request): - ban_list = Ban.objects.order_by('date_start') + ban_list = Ban.objects.order_by('date_start').reverse() + paginator = Paginator(ban_list, PAGINATION_NUMBER) + page = request.GET.get('page') + try: + ban_list = paginator.page(page) + except PageNotAnInteger: + # If page isn't an integer, deliver first page + ban_list = paginator.page(1) + except EmptyPage: + # If page is out of range (e.g. 9999), deliver last page of results. + ban_list = paginator.page(paginator.num_pages) return render(request, 'users/index_ban.html', {'ban_list': ban_list}) @login_required