From fbd685747b55d04fe5baeaebd896c50adcaf34c4 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Tue, 19 Sep 2017 04:45:33 +0200 Subject: [PATCH] FIx paginateur sur les whitelist --- users/models.py | 6 ++++++ users/templates/users/aff_bans.html | 6 +++++- users/templates/users/aff_whitelists.html | 10 +++++++++- users/views.py | 12 ++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/users/models.py b/users/models.py index fbe37494..3e3ceb35 100644 --- a/users/models.py +++ b/users/models.py @@ -668,6 +668,9 @@ class Ban(models.Model): general_options.email_from, [self.user.email], fail_silently=False) return + def is_active(self): + return self.date_end > now + def __str__(self): return str(self.user) + ' ' + str(self.raison) @@ -702,6 +705,9 @@ class Whitelist(models.Model): date_start = models.DateTimeField(auto_now_add=True) date_end = models.DateTimeField(help_text='%d/%m/%y %H:%M:%S') + def is_active(self): + return self.date_end > now + def __str__(self): return str(self.user) + ' ' + str(self.raison) diff --git a/users/templates/users/aff_bans.html b/users/templates/users/aff_bans.html index 617d148a..360cac70 100644 --- a/users/templates/users/aff_bans.html +++ b/users/templates/users/aff_bans.html @@ -37,7 +37,11 @@ with this program; if not, write to the Free Software Foundation, Inc., {% for ban in ban_list %} - + {% if ban.is_active %} + + {% else %} + + {% endif %} {{ ban.user }} {{ ban.raison }} {{ ban.date_start }} diff --git a/users/templates/users/aff_whitelists.html b/users/templates/users/aff_whitelists.html index 0842a277..fea90278 100644 --- a/users/templates/users/aff_whitelists.html +++ b/users/templates/users/aff_whitelists.html @@ -22,6 +22,10 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. {% endcomment %} +{% if white_list.paginator %} +{% include "pagination.html" with list=white_list %} +{% endif %} + @@ -33,7 +37,11 @@ with this program; if not, write to the Free Software Foundation, Inc., {% for whitelist in white_list %} - + {% if whitelist.is_active %} + + {% else %} + + {% endif %} diff --git a/users/views.py b/users/views.py index f766f4df..4f795b63 100644 --- a/users/views.py +++ b/users/views.py @@ -527,7 +527,19 @@ def index_ban(request): @permission_required('cableur') def index_white(request): """ Affiche l'ensemble des whitelist, need droit cableur """ + options, created = GeneralOption.objects.get_or_create() + pagination_number = options.pagination_number white_list = Whitelist.objects.select_related('user').order_by('date_start') + paginator = Paginator(white_list, pagination_number) + page = request.GET.get('page') + try: + white_list = paginator.page(page) + except PageNotAnInteger: + # If page isn't an integer, deliver first page + white_list = paginator.page(1) + except EmptyPage: + # If page is out of range (e.g. 9999), deliver last page of results. + white_list = paginator.page(paginator.num_pages) return render( request, 'users/index_whitelist.html',
{{ whitelist.user }} {{ whitelist.raison }} {{ whitelist.date_start }}