diff options
author | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2011-03-22 14:37:10 (GMT) |
---|---|---|
committer | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2011-03-22 14:37:10 (GMT) |
commit | a48df664dd9da38b02b3dc0c82a7eb4969db5b96 (patch) | |
tree | ea9a5518bf673886873551e0c610feba71f40858 /program | |
parent | bc4e14f6bd7b8df7988f547a02aa52f8065c6e43 (diff) |
added week schedule view.
Diffstat (limited to 'program')
-rw-r--r-- | program/urls.py | 3 | ||||
-rw-r--r-- | program/views.py | 42 |
2 files changed, 42 insertions, 3 deletions
diff --git a/program/urls.py b/program/urls.py index 318ae99..6e7da79 100644 --- a/program/urls.py +++ b/program/urls.py @@ -3,11 +3,12 @@ from django.views.generic.detail import DetailView from django.views.generic.list import ListView from models import Host, Show, TimeSlot -from views import CurrentShowView, DayScheduleView, RecommendationsView, ShowListView, TodayScheduleView +from views import CurrentShowView, DayScheduleView, RecommendationsView, ShowListView, TodayScheduleView, WeekScheduleView urlpatterns = patterns('', ('^$', TodayScheduleView.as_view()), ('^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', DayScheduleView.as_view()), + ('^(?P<year>\d{4})/(?P<week>\d{1,2})/$', WeekScheduleView.as_view()), ('^current/$', CurrentShowView.as_view()), ('^hosts/$', ListView.as_view(model=Host, context_object_name='hosts')), url('^host/(?P<pk>\d+)/$', DetailView.as_view(model=Host), name='host-detail'), diff --git a/program/views.py b/program/views.py index a9eabbc..1fa84af 100644 --- a/program/views.py +++ b/program/views.py @@ -1,6 +1,6 @@ from django.views.generic.list import ListView from django.views.generic.base import TemplateView -from django.views.generic.dates import DayArchiveView, TodayArchiveView +from django.views.generic.dates import DayArchiveView, TodayArchiveView, WeekArchiveView from django.shortcuts import get_object_or_404 from models import BroadcastFormat, MusicFocus, Note, Show, ShowInformation, ShowTopic, TimeSlot @@ -98,4 +98,42 @@ class CurrentShowView(TemplateView): context['next'] = TimeSlot.objects.get_or_create_current().get_next_by_start() context['after_next'] = TimeSlot.objects.get_or_create_current().get_next_by_start().get_next_by_start() - return context
\ No newline at end of file + return context + +class WeekScheduleView(TemplateView): + template_name = 'program/week_schedule.html' + + def get_context_data(self, **kwargs): + context = super(WeekScheduleView, self).get_context_data(**kwargs) + + year = context['params']['year'] + week = context['params']['week'] + + # start the day at 6 + monday = datetime.strptime('%s__%s__1__06__00' % (year, week), '%Y__%W__%w__%H__%M') + + tuesday = monday+timedelta(days=1) + wednesday = monday+timedelta(days=2) + thursday = monday+timedelta(days=3) + friday = monday+timedelta(days=4) + saturday = monday+timedelta(days=5) + sunday = monday+timedelta(days=6) + next_monday = monday+timedelta(days=7) + + context['monday'] = monday + context['tuesday'] = tuesday + context['wednesday'] = wednesday + context['thursday'] = thursday + context['friday'] = friday + context['saturday'] = saturday + context['sunday'] = sunday + + context['monday_timeslots'] = TimeSlot.objects.filter(start__range=(monday, tuesday)) + context['tuesday_timeslots'] = TimeSlot.objects.filter(start__range=(tuesday, wednesday)) + context['wednesday_timeslots'] = TimeSlot.objects.filter(start__range=(wednesday, thursday)) + context['thursday_timeslots'] = TimeSlot.objects.filter(start__range=(thursday, friday)) + context['friday_timeslots'] = TimeSlot.objects.filter(start__range=(friday, saturday)) + context['saturday_timeslots'] = TimeSlot.objects.filter(start__range=(saturday, sunday)) + context['sunday_timeslots'] = TimeSlot.objects.filter(start__range=(sunday, next_monday)) + + return context |