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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
import json
from datetime import date, datetime, time, timedelta
from django.db.models import Q
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.views.generic.base import TemplateView
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from models import BroadcastFormat, MusicFocus, Note, Show, ShowInformation, ShowTopic, Language, TimeSlot, Host
from program.utils import tofirstdayinisoweek, get_cached_shows
# Legacy Views for Homepage until 2021
class HostListView(ListView):
context_object_name = 'host_list'
queryset = Host.objects.filter(Q(is_always_visible=True) | Q(shows__programslots__until__gt=datetime.now)).distinct()
template_name = 'host_list.html'
class HostDetailView(DetailView):
context_object_name = 'host'
queryset = Host.objects.all()
template_name = 'host_detail.html'
class ShowListView(ListView):
context_object_name = 'show_list'
template_name = 'show_list.html'
def get_queryset(self):
queryset = Show.objects.filter(programslots__until__gt=date.today()).exclude(id=1).distinct()
if 'broadcastformat' in self.request.GET:
broadcastformat = get_object_or_404(BroadcastFormat, slug=self.request.GET['broadcastformat'])
queryset = queryset.filter(broadcastformat=broadcastformat)
elif 'musicfocus' in self.request.GET:
musicfocus = get_object_or_404(MusicFocus, slug=self.request.GET['musicfocus'])
queryset = queryset.filter(musicfocus=musicfocus)
elif 'showinformation' in self.request.GET:
showinformation = get_object_or_404(ShowInformation, slug=self.request.GET['showinformation'])
queryset = queryset.filter(showinformation=showinformation)
elif 'showtopic' in self.request.GET:
showtopic = get_object_or_404(ShowTopic, slug=self.request.GET['showtopic'])
queryset = queryset.filter(showtopic=showtopic)
elif 'language' in self.request.GET:
language = get_object_or_404(Language, slug=self.request.GET['language'])
queryset = queryset.filter(language=language)
return queryset
class ShowDetailView(DetailView):
queryset = Show.objects.all().exclude(id=1)
template_name = 'show_detail.html'
class TimeSlotDetailView(DetailView):
queryset = TimeSlot.objects.all()
template_name = 'timeslot_detail.html'
class RecommendationsListView(ListView):
context_object_name = 'recommendation_list'
template_name = 'recommendation_list.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]
class RecommendationsBoxView(RecommendationsListView):
template_name = 'boxes/recommendation.html'
class DayScheduleView(TemplateView):
template_name = 'day_schedule.html'
def get_context_data(self, **kwargs):
year = self.kwargs.get('year', None)
month = self.kwargs.get('month', None)
day = self.kwargs.get('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)
context = super(DayScheduleView, self).get_context_data(**kwargs)
context['day'] = today
context['recommendations'] = Note.objects.filter(status=1, timeslot__start__range=(today, tomorrow))
context['default_show'] = Show.objects.get(pk=1)
timeslots = TimeSlot.objects.get_day_timeslots(today)
if 'broadcastformat' in self.request.GET:
broadcastformat = get_object_or_404(BroadcastFormat, slug=self.request.GET['broadcastformat'])
context['timeslots'] = timeslots.filter(show__broadcastformat=broadcastformat)
elif 'musicfocus' in self.request.GET:
musicfocus = get_object_or_404(MusicFocus, slug=self.request.GET['musicfocus'])
context['timeslots'] = timeslots.filter(show__musicfocus=musicfocus)
elif 'showinformation' in self.request.GET:
showinformation = get_object_or_404(ShowInformation, slug=self.request.GET['showinformation'])
context['timeslots'] = timeslots.filter(show__showinformation=showinformation)
elif 'showtopic' in self.request.GET:
showtopic = get_object_or_404(ShowTopic, slug=self.request.GET['showtopic'])
context['showtopic'] = timeslots.filter(show__showtopic=showtopic)
elif 'language' in self.request.GET:
language = get_object_or_404(Language, slug=self.request.GET['language'])
context['showtopic'] = timeslots.filter(show__language=language)
else:
context['timeslots'] = timeslots
return context
class CurrentShowBoxView(TemplateView):
context_object_name = 'recommendation_list'
template_name = 'boxes/current.html'
def get_context_data(self, **kwargs):
current_timeslot = TimeSlot.objects.get_or_create_current()
previous_timeslot = current_timeslot.get_previous_by_start()
next_timeslot = current_timeslot.get_next_by_start()
after_next_timeslot = next_timeslot.get_next_by_start()
context = super(CurrentShowBoxView, self).get_context_data(**kwargs)
context['current_timeslot'] = current_timeslot
context['previous_timeslot'] = previous_timeslot
context['next_timeslot'] = next_timeslot
context['after_next_timeslot'] = after_next_timeslot
return context
class WeekScheduleView(TemplateView):
template_name = 'week_schedule.html'
def get_context_data(self, **kwargs):
year = self.kwargs.get('year', None)
week = self.kwargs.get('week', None)
if year is None and week is None:
year, week = datetime.now().strftime('%G__%V').split('__')
monday = tofirstdayinisoweek(int(year), int(week))
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)
context = super(WeekScheduleView, self).get_context_data()
context['monday'] = monday
context['tuesday'] = tuesday
context['wednesday'] = wednesday
context['thursday'] = thursday
context['friday'] = friday
context['saturday'] = saturday
context['sunday'] = sunday
context['default_show'] = Show.objects.get(pk=1)
context['monday_timeslots'] = TimeSlot.objects.get_day_timeslots(monday)
context['tuesday_timeslots'] = TimeSlot.objects.get_day_timeslots(tuesday)
context['wednesday_timeslots'] = TimeSlot.objects.get_day_timeslots(wednesday)
context['thursday_timeslots'] = TimeSlot.objects.get_day_timeslots(thursday)
context['friday_timeslots'] = TimeSlot.objects.get_day_timeslots(friday)
context['saturday_timeslots'] = TimeSlot.objects.get_day_timeslots(saturday)
context['sunday_timeslots'] = TimeSlot.objects.get_day_timeslots(sunday)
context['last_w'] = datetime.strftime(monday - timedelta(days=7), '%G/%V')
context['current_year'] = datetime.strftime(monday, '%G')
context['current_week'] = datetime.strftime(monday, '%V')
context['cur_w'] = datetime.strftime(monday, '%G/%V')
context['next_w1'] = datetime.strftime(monday + timedelta(days=7), '%G/%V')
context['next_w2'] = datetime.strftime(monday + timedelta(days=14), '%G/%V')
context['next_w3'] = datetime.strftime(monday + timedelta(days=21), '%G/%V')
context['next_w4'] = datetime.strftime(monday + timedelta(days=28), '%G/%V')
return context
class StylesView(TemplateView):
template_name = 'styles.css'
content_type = 'text/css'
def get_context_data(self, **kwargs):
context = super(StylesView, self).get_context_data(**kwargs)
context['broadcastformats'] = BroadcastFormat.objects.filter(enabled=True)
context['musicfocus'] = MusicFocus.objects.all()
context['showinformation'] = ShowInformation.objects.all()
context['showtopic'] = ShowTopic.objects.all()
return context
# V2 Views added for new Homepage 2021
class HostListViewV2(ListView):
context_object_name = 'host_list'
queryset = Host.objects.filter(Q(is_always_visible=True) | Q(shows__programslots__until__gt=datetime.now)).distinct()
template_name = 'v2/host_list.html'
class HostDetailViewV2(DetailView):
context_object_name = 'host'
queryset = Host.objects.all()
template_name = 'v2/host_detail.html'
class ShowListViewV2(ListView):
context_object_name = 'show_list'
template_name = 'v2/show_list.html'
def get_queryset(self):
queryset = Show.objects.filter(programslots__until__gt=date.today()).exclude(id=1).distinct()
if 'broadcastformat' in self.request.GET:
broadcastformat = get_object_or_404(BroadcastFormat, slug=self.request.GET['broadcastformat'])
queryset = queryset.filter(broadcastformat=broadcastformat)
elif 'musicfocus' in self.request.GET:
musicfocus = get_object_or_404(MusicFocus, slug=self.request.GET['musicfocus'])
queryset = queryset.filter(musicfocus=musicfocus)
elif 'showinformation' in self.request.GET:
showinformation = get_object_or_404(ShowInformation, slug=self.request.GET['showinformation'])
queryset = queryset.filter(showinformation=showinformation)
elif 'showtopic' in self.request.GET:
showtopic = get_object_or_404(ShowTopic, slug=self.request.GET['showtopic'])
queryset = queryset.filter(showtopic=showtopic)
elif 'language' in self.request.GET:
language = get_object_or_404(Language, slug=self.request.GET['language'])
queryset = queryset.filter(language=language)
return queryset
class ShowDetailViewV2(DetailView):
queryset = Show.objects.all().exclude(id=1)
template_name = 'v2/show_detail.html'
class TimeSlotDetailViewV2(DetailView):
queryset = TimeSlot.objects.all()
template_name = 'v2/timeslot_detail.html'
class RecommendationsListViewV2(ListView):
context_object_name = 'recommendation_list'
template_name = 'v2/recommendation_list.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]
class DayScheduleViewV2(TemplateView):
template_name = 'v2/day_schedule.html'
def get_context_data(self, **kwargs):
year = self.kwargs.get('year', None)
month = self.kwargs.get('month', None)
day = self.kwargs.get('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)
context = super(DayScheduleViewV2, self).get_context_data(**kwargs)
context['day'] = today
context['recommendations'] = Note.objects.filter(status=1, timeslot__start__range=(today, tomorrow))
context['default_show'] = Show.objects.get(pk=1)
timeslots = TimeSlot.objects.get_day_timeslots(today)
if 'broadcastformat' in self.request.GET:
broadcastformat = get_object_or_404(BroadcastFormat, slug=self.request.GET['broadcastformat'])
context['timeslots'] = timeslots.filter(show__broadcastformat=broadcastformat)
elif 'musicfocus' in self.request.GET:
musicfocus = get_object_or_404(MusicFocus, slug=self.request.GET['musicfocus'])
context['timeslots'] = timeslots.filter(show__musicfocus=musicfocus)
elif 'showinformation' in self.request.GET:
showinformation = get_object_or_404(ShowInformation, slug=self.request.GET['showinformation'])
context['timeslots'] = timeslots.filter(show__showinformation=showinformation)
elif 'showtopic' in self.request.GET:
showtopic = get_object_or_404(ShowTopic, slug=self.request.GET['showtopic'])
context['showtopic'] = timeslots.filter(show__showtopic=showtopic)
elif 'language' in self.request.GET:
language = get_object_or_404(Language, slug=self.request.GET['language'])
context['showtopic'] = timeslots.filter(show__language=language)
else:
context['timeslots'] = timeslots
return context
class ShowFilterListViewV2(TemplateView):
template_name = 'v2/show_filters.html'
# Exports
def json_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(0, 0))
else:
today = datetime.strptime('%s__%s__%s__00__00' % (year, month, day), '%Y__%m__%d__%H__%M')
timeslots = TimeSlot.objects.get_24h_timeslots(today).select_related('programslot').select_related('show')
schedule = []
for ts in timeslots:
entry = {
'start': ts.start.strftime('%Y-%m-%d_%H:%M:%S'),
'end': ts.end.strftime('%Y-%m-%d_%H:%M:%S'),
'title': ts.show.name,
'id': ts.show.id,
'automation-id': -1
}
if ts.programslot.automation_id:
entry['automation-id'] = ts.programslot.automation_id
schedule.append(entry)
return HttpResponse(json.dumps(schedule, ensure_ascii=False, encoding='utf8').encode('utf8'),
content_type="application/json; charset=utf-8")
def json_timeslots_specials(request):
specials = {}
shows = get_cached_shows()['shows']
for show in shows:
show['pv_id'] = -1
if show['type'] == 's':
specials[show['id']] = show
for ts in TimeSlot.objects.filter(end__gt=datetime.now, programslot__automation_id__in=specials.iterkeys()).select_related('show'):
automation_id = ts.programslot.automation_id
start = ts.start.strftime('%Y-%m-%d_%H:%M:%S')
end = ts.end.strftime('%Y-%m-%d_%H:%M:%S')
if specials[automation_id]['pv_id'] != -1:
if specials[automation_id]['pv_start'] < start:
continue
specials[automation_id]['pv_id'] = int(ts.show.id)
specials[automation_id]['pv_name'] = ts.show.name
specials[automation_id]['pv_start'] = start
specials[automation_id]['pv_end'] = end
return HttpResponse(json.dumps(specials, ensure_ascii=False, encoding='utf8').encode('utf8'),
content_type="application/json; charset=utf-8")
|