# 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 class YearView(TemplateView): ''' Display a year worth of BOcals ''' template_name = 'mainsite/year_view.html' def get_context_data(self, year, nYear, **kwargs): context = super(YearView, self).get_context_data(**kwargs) if year + 1 != nYear: raise Http404 publications = Publication.objects.filter( date__ge=datetime(year, 8, 1), date__lt=datetime(nYear, 8, 1)) if len(publications) == 0: raise Http404 context['publications'] = publications return context