Add a simple view for a year
This commit is contained in:
parent
aa4812e337
commit
10f29d8264
2 changed files with 30 additions and 2 deletions
7
mainsite/urls.py
Normal file
7
mainsite/urls.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
from django.conf.urls import url
|
||||||
|
from .views import YearView
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
url(r'^(?P<year>\d{4})-(?P<nYear>\d{4})/',
|
||||||
|
YearView.as_view(), name='year_view'),
|
||||||
|
]
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue