Add url for the latest publication

This commit is contained in:
Théophile Bastian 2017-09-24 19:11:08 +02:00
parent 23466d3717
commit dd95ce4c3c
2 changed files with 8 additions and 1 deletions

View file

@ -8,4 +8,5 @@ urlpatterns = [
name='special_publications'), name='special_publications'),
url(r'^(?P<year>\d{4})-(?P<nYear>\d{4})/', url(r'^(?P<year>\d{4})-(?P<nYear>\d{4})/',
views.YearView.as_view(), name='year_view'), views.YearView.as_view(), name='year_view'),
url(r'^latest$', views.latestPublication, name='latestPublication'),
] ]

View file

@ -1,4 +1,4 @@
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404, redirect
from django.views.generic import TemplateView from django.views.generic import TemplateView
from django.http import Http404 from django.http import Http404
@ -83,3 +83,9 @@ class SpecialPublicationsView(PublicationListView):
.filter(is_special=True)\ .filter(is_special=True)\
.order_by('-date') .order_by('-date')
return publications return publications
def latestPublication(req):
''' Redirects to the latest standard publication '''
latestPubli = Publication.latest()
return redirect(latestPubli.url)