From 0c34bc8f3efe36c2bf0be0bcb61be670a790e939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Thu, 21 Sep 2017 19:38:49 +0200 Subject: [PATCH] Fix YearView filters and types --- mainsite/views.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mainsite/views.py b/mainsite/views.py index a7a83e4..2c25770 100644 --- a/mainsite/views.py +++ b/mainsite/views.py @@ -1,8 +1,10 @@ # from django.shortcuts import render from django.views.generic import TemplateView -from mainsite.models import Publication from django.http import Http404 -from datetime import datetime + +from datetime import date + +from mainsite.models import Publication class YearView(TemplateView): @@ -11,12 +13,17 @@ class YearView(TemplateView): def get_context_data(self, year, nYear, **kwargs): context = super(YearView, self).get_context_data(**kwargs) + + try: + year, nYear = int(year), int(nYear) + except ValueError: + raise Http404 if year + 1 != nYear: raise Http404 publications = Publication.objects.filter( - date__ge=datetime(year, 8, 1), - date__lt=datetime(nYear, 8, 1)) + date__gte=date(year, 8, 1), + date__lt=date(nYear, 8, 1)) if len(publications) == 0: raise Http404 context['publications'] = publications