From 02207c48461f1c850b434e688ec12a13598d60bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sat, 1 Nov 2014 16:40:31 +0100 Subject: [PATCH] redirect nonstop home to current day --- nonstop/urls.py | 3 ++- nonstop/views.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/nonstop/urls.py b/nonstop/urls.py index 08dc88d..82f4d77 100644 --- a/nonstop/urls.py +++ b/nonstop/urls.py @@ -1,9 +1,10 @@ from django.conf.urls import url -from .views import SomaDayArchiveView +from .views import SomaDayArchiveView, RedirectTodayView urlpatterns = [ # Example: /2012/nov/10/ + url(r'^$', RedirectTodayView.as_view()), url(r'^(?P[0-9]{4})/(?P[-\w]+)/(?P[0-9]+)/$', SomaDayArchiveView.as_view(), name="archive_day"), diff --git a/nonstop/views.py b/nonstop/views.py index 3ade872..6e28e00 100644 --- a/nonstop/views.py +++ b/nonstop/views.py @@ -1,3 +1,7 @@ +import datetime + +from django.core.urlresolvers import reverse +from django.views.generic.base import RedirectView from django.views.generic.dates import DayArchiveView from .models import SomaLogLine @@ -7,3 +11,13 @@ class SomaDayArchiveView(DayArchiveView): date_field = "play_timestamp" make_object_list = True allow_future = False + month_format = '%m' + + +class RedirectTodayView(RedirectView): + def get_redirect_url(self, *args, **kwargs): + today = datetime.datetime.today() + return reverse('archive_day', kwargs={ + 'year': today.year, + 'month': today.month, + 'day': today.day}) -- GitLab