diff --git a/mainsite/urls.py b/mainsite/urls.py new file mode 100644 index 0000000..a41c5cb --- /dev/null +++ b/mainsite/urls.py @@ -0,0 +1,7 @@ +from django.conf.urls import url +from .views import YearView + +urlpatterns = [ + url(r'^(?P\d{4})-(?P\d{4})/', + YearView.as_view(), name='year_view'), +] diff --git a/mainsite/views.py b/mainsite/views.py index 91ea44a..a7a83e4 100644 --- a/mainsite/views.py +++ b/mainsite/views.py @@ -1,3 +1,24 @@ -from django.shortcuts import render +# 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 -# Create your views here. + +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