summaryrefslogtreecommitdiff
path: root/helsinki
diff options
context:
space:
mode:
authorErnesto Rico-Schmidt <e.rico.schmidt@gmail.com>2011-04-10 16:21:44 (GMT)
committerErnesto Rico-Schmidt <e.rico.schmidt@gmail.com>2011-04-10 16:21:44 (GMT)
commitbb852483864a5c1be8cd99d2e05a3b1fc0ce0d5c (patch)
treee676cccf187ff89735c585142586c28fb4b326e1 /helsinki
parent055afc7d47fcd147274dba884156523d8ff69bbf (diff)
cleaned-up URL and views. implemented /week URL.
Diffstat (limited to 'helsinki')
-rw-r--r--helsinki/program/templates/program/broadcastformats_box.html (renamed from helsinki/program/templates/program/bcformats_box.html)6
-rw-r--r--helsinki/program/urls.py4
-rw-r--r--helsinki/program/urls_program.py51
-rw-r--r--helsinki/program/views.py47
4 files changed, 52 insertions, 56 deletions
diff --git a/helsinki/program/templates/program/bcformats_box.html b/helsinki/program/templates/program/broadcastformats_box.html
index 3067805..13fb0a9 100644
--- a/helsinki/program/templates/program/bcformats_box.html
+++ b/helsinki/program/templates/program/broadcastformats_box.html
@@ -6,10 +6,10 @@
<link href="/site_media/styles/base.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
- {% if broadcastformats %}
+ {% if broadcastformat_list %}
<dl id="bcformats" class="portlet program-bcformats">
- <dt class="portletHeader"><span>Legende<span></dt>
- {% for broadcastformat in broadcastformats %}
+ <dt class="portletHeader"><span>Legende</span></dt>
+ {% for broadcastformat in broadcastformat_list %}
<dd class="portletItem bcformat bcformat-{{ broadcastformat.slug }}">
<a href="?broadcastformat={{ broadcastformat.slug }}">{{ broadcastformat.format }}</a>
</dd>
diff --git a/helsinki/program/urls.py b/helsinki/program/urls.py
index 341923b..f90a332 100644
--- a/helsinki/program/urls.py
+++ b/helsinki/program/urls.py
@@ -7,8 +7,8 @@ import os
admin.autodiscover()
urlpatterns = patterns('',
- (r'^admin/', include(admin.site.urls)),
- (r'^program', include('helsinki.program.urls_program')),
+ (r'^admin/', include(admin.site.urls)),
+ (r'^program/', include('helsinki.program.urls_program')),
)
if settings.DEBUG:
urlpatterns += patterns('',
diff --git a/helsinki/program/urls_program.py b/helsinki/program/urls_program.py
index 8b83d6d..5462e10 100644
--- a/helsinki/program/urls_program.py
+++ b/helsinki/program/urls_program.py
@@ -2,23 +2,40 @@ from django.conf.urls.defaults import *
from django.views.generic.list_detail import object_detail, object_list
-from models import Host, Show, TimeSlot
-from views import current_show, day_schedule, recommendations, show_list, today_schedule, week_schedule, bcformats
+from models import BroadcastFormat, Host, Show, TimeSlot
+from views import current_show, day_schedule, recommendations, show_list, week_schedule
+
+host_dict = {
+ 'queryset': Host.objects.all(),
+ 'template_object_name': 'host'
+}
+show_dict = {
+ 'queryset': Show.objects.all(),
+ 'template_object_name': 'show'
+}
+timeslot_dict = {
+ 'queryset': TimeSlot.objects.all(),
+ 'template_object_name': 'timeslot'
+}
+broadcastformart_dict = {
+ 'queryset': BroadcastFormat.objects.all(),
+ 'template_name': 'program/broadcastformats_box.html',
+ 'template_object_name': 'broadcastformat'
+}
+recommendation_dict = {'template_name': 'program/recommendations_box.html'}
urlpatterns = patterns('',
- ('^/today/?$', today_schedule),
- ('^/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/?$', day_schedule),
- ('^/(?P<year>\d{4})/(?P<week>\d{1,2})/?$', week_schedule),
- ('^/current_box/?$', current_show),
- ('^/hosts/?$', object_list, dict(template_object_name='host', queryset=Host.objects.all())),
- url('^/hosts/(?P<object_id>\d+)/?$', object_detail, dict(template_object_name='host', queryset=Host.objects.all()), name='host-detail'),
- ('^/tips/?$', recommendations),
- ('^/tips_box/?$', recommendations, dict(template_name='program/recommendations_box.html')),
- ('^/shows/?$', show_list),
- url('^/shows/(?P<slug>[\w-]+)/?$', object_detail, dict(template_object_name='show', queryset=Show.objects.all()), name='show-detail'),
- url('^/(?P<object_id>\d+)/?$', object_detail, dict(template_object_name='timeslot', queryset=TimeSlot.objects.all()), name='timeslot-detail'),
- ('^/bcformats_box/?$', bcformats),
- # TODO: implement
- ('^/week/?$', today_schedule),
- ('^/broadcast_formats/?$', recommendations),
+ (r'^today/?$', day_schedule),
+ (r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/?$', day_schedule),
+ (r'^(?P<year>\d{4})/(?P<week>\d{1,2})/?$', week_schedule),
+ (r'^current_box/?$', current_show),
+ (r'^hosts/?$', object_list, host_dict),
+ url(r'^hosts/(?P<object_id>\d+)/?$', object_detail, host_dict, name='host-detail'),
+ (r'^tips/?$', recommendations),
+ (r'^tips_box/?$', recommendations, recommendation_dict),
+ (r'^shows/?$', show_list),
+ url(r'^shows/(?P<slug>[\w-]+)/?$', object_detail, show_dict, name='show-detail'),
+ url(r'^(?P<object_id>\d+)/?$', object_detail, timeslot_dict, name='timeslot-detail'),
+ (r'^broadcastformats_box/?$', object_list, broadcastformart_dict,),
+ (r'^week/?$', week_schedule)
)
diff --git a/helsinki/program/views.py b/helsinki/program/views.py
index 584f24d..48b5d5f 100644
--- a/helsinki/program/views.py
+++ b/helsinki/program/views.py
@@ -33,7 +33,6 @@ def show_list(request):
else:
queryset = Show.objects.all()
-
return list_detail.object_list(request, queryset=queryset, extra_context=extra_context, template_object_name='show')
def recommendations(request, template_name='program/recommendations.html'):
@@ -44,13 +43,16 @@ def recommendations(request, template_name='program/recommendations.html'):
return list_detail.object_list(request, queryset=queryset, template_name=template_name, template_object_name='recommendation')
-def today_schedule(request):
- now = datetime.now()
- today = datetime.combine(date.today(), time(6, 0))
- tomorrow = today + timedelta(days=1)
+def day_schedule(request, year=None, month=None, day=None):
+ if year is None and month is None and day is None:
+ today = datetime.combine(date.today(), time(6, 0))
+ else:
+ today = datetime.strptime('%s__%s__%s__06__00' % (year, month, day), '%Y__%m__%d__%H__%M')
+
+ tomorrow = today+timedelta(days=1)
broadcastformats = BroadcastFormat.objects.all()
- recommendations = Note.objects.filter(status=1, timeslot__start__range=(now, tomorrow))
+ recommendations = Note.objects.filter(status=1, timeslot__start__range=(today, tomorrow))
extra_context = dict(day=today, broadcastformats=broadcastformats, recommendations=recommendations)
@@ -63,24 +65,6 @@ def today_schedule(request):
return simple.direct_to_template(request, extra_context=extra_context, template='program/day_schedule.html')
-def day_schedule(request, year, month, day):
- this_day = datetime.strptime('%s__%s__%s__06__00' % (year, month, day), '%Y__%m__%d__%H__%M')
- that_day = this_day+timedelta(days=1)
-
- broadcastformats = BroadcastFormat.objects.all()
- recommendations = Note.objects.filter(status=1, timeslot__start__range=(this_day, that_day))
-
- extra_context = dict(day=this_day, broadcastformats=broadcastformats, recommendations=recommendations)
-
- if 'broadcastformat' in request.GET:
- broadcastformat = get_object_or_404(BroadcastFormat, slug=request.GET['broadcastformat'])
-
- extra_context['timeslots'] = TimeSlot.objects.filter(start__range=(this_day, that_day), show__broadcastformat=broadcastformat)
- else:
- extra_context['timeslots'] = TimeSlot.objects.filter(start__range=(this_day, that_day))
-
- return simple.direct_to_template(request, extra_context=extra_context, template='program/day_schedule.html')
-
def current_show(request):
current = TimeSlot.objects.get_or_create_current()
next = current.get_next_by_start()
@@ -90,8 +74,12 @@ def current_show(request):
return simple.direct_to_template(request, template='program/current_box.html', extra_context=extra_context)
-def week_schedule(request, year, week):
+def week_schedule(request, year=None, week=None):
+ if year is None and week is None:
+ year, week = datetime.strftime(datetime.today(), '%Y__%W').split('__')
+
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)
@@ -111,12 +99,3 @@ def week_schedule(request, year, week):
extra_context['sunday_timeslots'] = TimeSlot.objects.filter(start__range=(sunday, next_monday))
return simple.direct_to_template(request, template='program/week_schedule.html', extra_context=extra_context)
-
-
-def bcformats(request):
- broadcastformats = BroadcastFormat.objects.all()
- extra_context = dict(broadcastformats=broadcastformats)
- return simple.direct_to_template(
- request,
- template='program/bcformats_box.html',
- extra_context=extra_context)