1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
from django.views.generic import list_detail, simple
from django.shortcuts import get_object_or_404
from django.db.models import Q
from models import BroadcastFormat, MusicFocus, Note, Show, ShowInformation, ShowTopic, TimeSlot
from datetime import date, datetime, time, timedelta
def show_list(request):
queryset = Show.objects.filter(programslots__until__gt=date.today()).exclude(id=1).distinct()
if 'broadcastformat' in request.GET:
broadcastformat = get_object_or_404(BroadcastFormat, slug=request.GET['broadcastformat'])
queryset = queryset.filter(broadcastformat=broadcastformat)
elif 'musicfocus' in request.GET:
musicfocus = get_object_or_404(MusicFocus, slug=request.GET['musicfocus'])
queryset = queryset.filter(musicfocus=musicfocus)
elif 'showinformation' in request.GET:
showinformation = get_object_or_404(ShowInformation, slug=request.GET['showinformation'])
queryset = queryset.filter(showinformation=showinformation)
elif 'showtopic' in request.GET:
showtopic = get_object_or_404(ShowTopic, slug=request.GET['showtopic'])
queryset = queryset.filter(showtopic=showtopic)
return list_detail.object_list(request, queryset=queryset, template_object_name='show')
def recommendations(request, template_name='program/recommendations.html'):
now = datetime.now()
end = now + timedelta(weeks=1)
queryset = TimeSlot.objects.filter(Q(note__isnull=False, note__status=1, start__range=(now, end)) |
Q(show__broadcastformat__slug='sondersendung', start__range=(now, end))).order_by('start')[:20]
return list_detail.object_list(request, queryset=queryset, template_name=template_name, template_object_name='recommendation')
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)
recommendations = Note.objects.filter(status=1, timeslot__start__range=(today, tomorrow))
default_show = Show.objects.get(pk=1)
extra_context = dict(day=today, recommendations=recommendations, default_show=default_show)
timeslots = TimeSlot.objects.get_day_timeslots(today)
if 'broadcastformat' in request.GET:
broadcastformat = get_object_or_404(BroadcastFormat, slug=request.GET['broadcastformat'])
extra_context['timeslots'] = timeslots.filter(show__broadcastformat=broadcastformat)
elif 'musicfocus' in request.GET:
musicfocus = get_object_or_404(MusicFocus, slug=request.GET['musicfocus'])
extra_context['timeslots'] = timeslots.filter(show__musicfocus=musicfocus)
elif 'showinformation' in request.GET:
showinformation = get_object_or_404(ShowInformation, slug=request.GET['showinformation'])
extra_context['timeslots'] = timeslots.filter(show__showinformation=showinformation)
elif 'showtopic' in request.GET:
showtopic = get_object_or_404(ShowTopic, slug=request.GET['showtopic'])
extra_context['showtopic'] = timeslots.filter(show__showtopic=showtopic)
else:
extra_context['timeslots'] = timeslots
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()
previous = current.get_previous_by_start()
next = current.get_next_by_start()
after_next = next.get_next_by_start()
extra_context = dict(current=current,
previous=previous,
next=next,
after_next=after_next)
return simple.direct_to_template(request, template='program/boxes/current.html', extra_context=extra_context)
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)
friday = monday+timedelta(days=4)
saturday = monday+timedelta(days=5)
sunday = monday+timedelta(days=6)
default_show = Show.objects.get(pk=1)
extra_context = dict(monday=monday, tuesday=tuesday, wednesday=wednesday, thursday=thursday, friday=friday, saturday=saturday, sunday=sunday, default_show=default_show)
extra_context['monday_timeslots'] = TimeSlot.objects.get_day_timeslots(monday)
extra_context['tuesday_timeslots'] = TimeSlot.objects.get_day_timeslots(tuesday)
extra_context['wednesday_timeslots'] = TimeSlot.objects.get_day_timeslots(wednesday)
extra_context['thursday_timeslots'] = TimeSlot.objects.get_day_timeslots(thursday)
extra_context['friday_timeslots'] = TimeSlot.objects.get_day_timeslots(friday)
extra_context['saturday_timeslots'] = TimeSlot.objects.get_day_timeslots(saturday)
extra_context['sunday_timeslots'] = TimeSlot.objects.get_day_timeslots(sunday)
extra_context['last_w'] = datetime.strftime(monday-timedelta(days=7), '%Y/%W')
extra_context['cur_w'] = '%s/%s' % (year, week)
extra_context['next_w1'] = datetime.strftime(monday+timedelta(days=7), '%Y/%W')
extra_context['next_w2'] = datetime.strftime(monday+timedelta(days=14), '%Y/%W')
extra_context['next_w3'] = datetime.strftime(monday+timedelta(days=21), '%Y/%W')
extra_context['next_w4'] = datetime.strftime(monday+timedelta(days=28), '%Y/%W')
return simple.direct_to_template(request, template='program/week_schedule.html', extra_context=extra_context)
|