www-bocal/mainsite/views.py
2017-09-22 13:44:36 +02:00

41 lines
1.1 KiB
Python

# from django.shortcuts import render
from django.views.generic import TemplateView
from django.http import Http404
from datetime import date
from mainsite.models import Publication
class HomeView(TemplateView):
''' Website's homepage '''
template_name = 'mainsite/homepage.html'
class WriteArticleView(TemplateView):
''' Tell the readers how they can contribute to the BOcal '''
template_name = 'mainsite/write_article.html'
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)
try:
year, nYear = int(year), int(nYear)
except ValueError:
raise Http404
if year + 1 != nYear:
raise Http404
publications = Publication.objects.filter(
date__gte=date(year, 8, 1),
date__lt=date(nYear, 8, 1))
if len(publications) == 0:
raise Http404
context['publications'] = publications
return context