Allow admins to see more days from sources

This commit is contained in:
Rodolphe Breard 2018-06-09 19:02:47 +02:00
parent 9f490febdf
commit 49c0cbf16e

View file

@ -106,15 +106,21 @@ class EntriesView(generic.ListView):
_, start_date, end_date = _get_dates() _, start_date, end_date = _get_dates()
if source is None: if source is None:
return [] return []
nb_max = settings.KHAGANAT_LOGS_MAX_DAYS - settings.KHAGANAT_LOGS_MIN_DAYS
lst = Entry.objects.filter( lst = Entry.objects.filter(
hidden=False,
source=source, 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') date=TruncDate('created')
).values('date').annotate( ).values('date').annotate(
nb=Count('date') nb=Count('date')
).order_by('-date') ).order_by('-date')[:nb_max]
return [o['date'] for o in lst] return [o['date'] for o in lst]
def get_source(self): def get_source(self):