2017-09-21 14:00:10 +02:00
|
|
|
# from django.shortcuts import render
|
|
|
|
from django.views.generic import TemplateView
|
|
|
|
from django.http import Http404
|
2017-09-21 19:38:49 +02:00
|
|
|
|
|
|
|
from datetime import date
|
|
|
|
|
|
|
|
from mainsite.models import Publication
|
2017-09-21 10:58:19 +02:00
|
|
|
|
2017-09-21 14:00:10 +02:00
|
|
|
|
2017-09-22 13:44:36 +02:00
|
|
|
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'
|
|
|
|
|
|
|
|
|
2017-09-21 14:00:10 +02:00
|
|
|
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)
|
2017-09-21 19:38:49 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
year, nYear = int(year), int(nYear)
|
|
|
|
except ValueError:
|
|
|
|
raise Http404
|
2017-09-21 14:00:10 +02:00
|
|
|
if year + 1 != nYear:
|
|
|
|
raise Http404
|
|
|
|
|
|
|
|
publications = Publication.objects.filter(
|
2017-09-21 19:38:49 +02:00
|
|
|
date__gte=date(year, 8, 1),
|
|
|
|
date__lt=date(nYear, 8, 1))
|
2017-09-21 14:00:10 +02:00
|
|
|
if len(publications) == 0:
|
|
|
|
raise Http404
|
|
|
|
context['publications'] = publications
|
|
|
|
|
|
|
|
return context
|