summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
Diffstat (limited to 'program')
-rw-r--r--program/urls.py9
-rw-r--r--program/views.py66
2 files changed, 65 insertions, 10 deletions
diff --git a/program/urls.py b/program/urls.py
index 128f95f..318ae99 100644
--- a/program/urls.py
+++ b/program/urls.py
@@ -3,14 +3,17 @@ from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from models import Host, Show, TimeSlot
-from views import RecommendationsView, ShowListView
+from views import CurrentShowView, DayScheduleView, RecommendationsView, ShowListView, TodayScheduleView
urlpatterns = patterns('',
- ('^hosts/$', ListView.as_view(model=Host, context_object_name='host_list')),
+ ('^$', TodayScheduleView.as_view()),
+ ('^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', DayScheduleView.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'),
('^recommendations/$', RecommendationsView.as_view()),
('^recommendations_box/$', RecommendationsView.as_view(template_name='program/recommendations_box.html')),
('^shows/$', ShowListView.as_view()),
url('^show/(?P<slug>[\w-]+)/$', DetailView.as_view(model=Show), name='show-detail'),
- url('^timeslot/(?P<pk>\d+)/$', DetailView.as_view(model=TimeSlot), name='timeslot-detail'),
+ url('^(?P<pk>\d+)/$', DetailView.as_view(model=TimeSlot), name='timeslot-detail'),
) \ No newline at end of file
diff --git a/program/views.py b/program/views.py
index 062ce6d..a9eabbc 100644
--- a/program/views.py
+++ b/program/views.py
@@ -1,20 +1,22 @@
from django.views.generic.list import ListView
+from django.views.generic.base import TemplateView
+from django.views.generic.dates import DayArchiveView, TodayArchiveView
from django.shortcuts import get_object_or_404
-from models import BroadcastFormat, MusicFocus, Note, Show, ShowInformation, ShowTopic
+from models import BroadcastFormat, MusicFocus, Note, Show, ShowInformation, ShowTopic, TimeSlot
-from datetime import datetime, timedelta
+from datetime import date, datetime, time, timedelta
class ShowListView(ListView):
- context_object_name = 'show_list'
+ context_object_name = 'shows'
def get_context_data(self, **kwargs):
context = super(ShowListView, self).get_context_data(**kwargs)
- context['broadcastformat_list'] = BroadcastFormat.objects.all()
- context['musicfocus_list'] = MusicFocus.objects.all()
- context['showinformation_list'] = ShowInformation.objects.all()
- context['showtopic_list'] = ShowTopic.objects.all()
+ context['broadcastformats'] = BroadcastFormat.objects.all()
+ context['musicfoci'] = MusicFocus.objects.all()
+ context['showinformations'] = ShowInformation.objects.all()
+ context['showtopics'] = ShowTopic.objects.all()
return context
@@ -47,3 +49,53 @@ class RecommendationsView(ListView):
in_one_week = now + timedelta(weeks=1)
return Note.objects.filter(status=1, timeslot__start__range=(now, in_one_week))[:10]
+
+class TodayScheduleView(TodayArchiveView):
+ model = TimeSlot
+ allow_future = True
+ date_field = 'start'
+ context_object_name = 'timeslots'
+ template_name = 'program/today_schedule.html'
+
+ def get_context_data(self, **kwargs):
+ context = super(TodayScheduleView, self).get_context_data(**kwargs)
+
+ now = datetime.now()
+ midnight = datetime.combine(date.today(), time(23, 59))
+
+ context['broadcastformats'] = BroadcastFormat.objects.all()
+ context['recommendations'] = Note.objects.filter(status=1, timeslot__start__range=(now, midnight))
+
+ return context
+
+class DayScheduleView(DayArchiveView):
+ model = TimeSlot
+ allow_future = True
+ date_field = 'start'
+ month_format = '%m'
+ context_object_name = 'timeslots'
+ template_name = 'program/day_schedule.html'
+
+ def get_context_data(self, **kwargs):
+ context = super(DayScheduleView, self).get_context_data(**kwargs)
+
+ year, month, day = map(int, [self.get_year(), self.get_month(), self.get_day()])
+ this_day = datetime(year, month, day, 0, 0)
+ midnight = datetime(year, month, day, 23, 59)
+
+ context['broadcastformats'] = BroadcastFormat.objects.all()
+ context['recommendations'] = Note.objects.filter(status=1, timeslot__start__range=(this_day, midnight))
+
+ return context
+
+class CurrentShowView(TemplateView):
+ template_name = 'program/current.html'
+
+ def get_context_data(self, **kwargs):
+ context = super(CurrentShowView, self).get_context_data(**kwargs)
+
+ context['current'] = TimeSlot.objects.get_or_create_current()
+ 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