From bb852483864a5c1be8cd99d2e05a3b1fc0ce0d5c Mon Sep 17 00:00:00 2001 From: Ernesto Rico-Schmidt Date: Sun, 10 Apr 2011 18:21:44 +0200 Subject: cleaned-up URL and views. implemented /week URL. diff --git a/helsinki/program/templates/program/bcformats_box.html b/helsinki/program/templates/program/bcformats_box.html deleted file mode 100644 index 3067805..0000000 --- a/helsinki/program/templates/program/bcformats_box.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - - Broadcast Formats - - - - {% if broadcastformats %} -
-
Legende
- {% for broadcastformat in broadcastformats %} -
- {{ broadcastformat.format }} -
- {% endfor %} -
- {% endif %} - - diff --git a/helsinki/program/templates/program/broadcastformats_box.html b/helsinki/program/templates/program/broadcastformats_box.html new file mode 100644 index 0000000..13fb0a9 --- /dev/null +++ b/helsinki/program/templates/program/broadcastformats_box.html @@ -0,0 +1,20 @@ + + + + + Broadcast Formats + + + + {% if broadcastformat_list %} +
+
Legende
+ {% for broadcastformat in broadcastformat_list %} +
+ {{ broadcastformat.format }} +
+ {% endfor %} +
+ {% endif %} + + 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\d{4})/(?P\d{1,2})/(?P\d{1,2})/?$', day_schedule), - ('^/(?P\d{4})/(?P\d{1,2})/?$', week_schedule), - ('^/current_box/?$', current_show), - ('^/hosts/?$', object_list, dict(template_object_name='host', queryset=Host.objects.all())), - url('^/hosts/(?P\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[\w-]+)/?$', object_detail, dict(template_object_name='show', queryset=Show.objects.all()), name='show-detail'), - url('^/(?P\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\d{4})/(?P\d{1,2})/(?P\d{1,2})/?$', day_schedule), + (r'^(?P\d{4})/(?P\d{1,2})/?$', week_schedule), + (r'^current_box/?$', current_show), + (r'^hosts/?$', object_list, host_dict), + url(r'^hosts/(?P\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[\w-]+)/?$', object_detail, show_dict, name='show-detail'), + url(r'^(?P\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) -- cgit v0.10.2