From 49c0cbf16e178442c6a3c1a8259b0ac15fa41b94 Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Sat, 9 Jun 2018 19:02:47 +0200 Subject: [PATCH] Allow admins to see more days from sources --- logs/views.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/logs/views.py b/logs/views.py index 7e9f6ce..c5c1780 100644 --- a/logs/views.py +++ b/logs/views.py @@ -106,15 +106,21 @@ class EntriesView(generic.ListView): _, start_date, end_date = _get_dates() if source is None: return [] + + nb_max = settings.KHAGANAT_LOGS_MAX_DAYS - settings.KHAGANAT_LOGS_MIN_DAYS lst = Entry.objects.filter( - hidden=False, source=source, - created__range=(start_date, end_date) - ).annotate( + ) + if not self.request.user.is_staff: + lst = lst.filter( + hidden=False, + created__range=(start_date, end_date) + ) + lst = lst.annotate( date=TruncDate('created') ).values('date').annotate( nb=Count('date') - ).order_by('-date') + ).order_by('-date')[:nb_max] return [o['date'] for o in lst] def get_source(self):