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