summaryrefslogtreecommitdiff
path: root/program/views.py
blob: 23c1483e615b3e8e02bd1acc3384f6474192ef52 (plain)
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
from django.views.generic.list import ListView
from django.views.generic.base import TemplateView
from django.shortcuts import get_object_or_404

from models import BroadcastFormat, MusicFocus, Note, Show, ShowInformation, ShowTopic, TimeSlot

from datetime import date, datetime, time, timedelta

class ShowListView(ListView):
    context_object_name = 'shows'

    def get_context_data(self, **kwargs):
        context = super(ShowListView, self).get_context_data(**kwargs)

        context['broadcastformats'] = BroadcastFormat.objects.all()
        context['musicfoci'] = MusicFocus.objects.all()
        context['showinformations'] = ShowInformation.objects.all()
        context['showtopics'] = ShowTopic.objects.all()

        return context

    def get_queryset(self):
        if 'broadcastformat' in self.request.GET:
            broadcastformat = get_object_or_404(BroadcastFormat, slug=self.request.GET['broadcastformat'])

            return Show.objects.filter(broadcastformat=broadcastformat)
        elif 'musicfocus' in self.request.GET:
            musicfocus = get_object_or_404(MusicFocus, slug=self.request.GET['musicfocus'])

            return Show.objects.filter(musicfocus=musicfocus)
        elif 'showinformation' in self.request.GET:
            showinformation = get_object_or_404(ShowInformation, slug=self.request.GET['showinformation'])

            return Show.objects.filter(showinformation=showinformation)
        elif 'showtopic' in self.request.GET:
            showtopic = get_object_or_404(ShowTopic, slug=self.request.GET['showtopic'])

            return Show.objects.filter(showtopic=showtopic)
        else:
            return Show.objects.all()

class RecommendationsView(ListView):
    context_object_name = 'recommendations'
    template_name = 'program/recommendations.html'

    def get_queryset(self):
        now = datetime.now()
        in_one_week = now + timedelta(weeks=1)

        return Note.objects.filter(status=1, timeslot__start__range=(now, in_one_week))[:10]

class TodayScheduleView(TemplateView):
    template_name = 'program/day_schedule.html'

    def get_context_data(self, **kwargs):
        context = super(TodayScheduleView, self).get_context_data(**kwargs)

        now = datetime.now()
        today = datetime.combine(date.today(), time(6, 0))
        tomorrow = datetime.combine(date.today()+timedelta(days=1), time(6, 0))

        context['day'] = today
        context['broadcastformats'] = BroadcastFormat.objects.all()
        context['recommendations'] = Note.objects.filter(status=1, timeslot__start__range=(now, tomorrow))

        if 'broadcastformat' in self.request.GET:
            broadcastformat = get_object_or_404(BroadcastFormat, slug=self.request.GET['broadcastformat'])

            context['timeslots'] = TimeSlot.objects.filter(start__range=(today, tomorrow), show__broadcastformat=broadcastformat)
        else:
            context['timeslots'] = TimeSlot.objects.filter(start__range=(today, tomorrow))

        return context

class DayScheduleView(TemplateView):
    template_name = 'program/day_schedule.html'

    def get_context_data(self, **kwargs):
        context = super(DayScheduleView, self).get_context_data(**kwargs)

        year = context['params']['year']
        month = context['params']['month']
        day = context['params']['day']

        # start the day at 6
        this_day = datetime.strptime('%s__%s__%s__06__00' % (year, month, day), '%Y__%m__%d__%H__%M')
        that_day = this_day+timedelta(days=1)

        context['day'] = this_day
        context['broadcastformats'] = BroadcastFormat.objects.all()
        context['recommendations'] = Note.objects.filter(status=1, timeslot__start__range=(this_day, that_day))

        if 'broadcastformat' in self.request.GET:
            broadcastformat = get_object_or_404(BroadcastFormat, slug=self.request.GET['broadcastformat'])

            context['timeslots'] = TimeSlot.objects.filter(start__range=(this_day, that_day), show__broadcastformat=broadcastformat)
        else:
            context['timeslots'] = TimeSlot.objects.filter(start__range=(this_day, that_day))

        return context
    
class CurrentShowView(TemplateView):
    template_name = 'program/current_box.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

class WeekScheduleView(TemplateView):
    template_name = 'program/week_schedule.html'

    def get_context_data(self, **kwargs):
        context = super(WeekScheduleView, self).get_context_data(**kwargs)

        year = context['params']['year']
        week = context['params']['week']

        # start the day at 6
        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)
        next_monday = monday+timedelta(days=7)

        context['monday'] = monday
        context['tuesday'] = tuesday
        context['wednesday'] = wednesday
        context['thursday'] = thursday
        context['friday'] = friday
        context['saturday'] = saturday
        context['sunday'] = sunday
        
        context['monday_timeslots'] = TimeSlot.objects.filter(start__range=(monday, tuesday))
        context['tuesday_timeslots'] = TimeSlot.objects.filter(start__range=(tuesday, wednesday))
        context['wednesday_timeslots'] = TimeSlot.objects.filter(start__range=(wednesday, thursday))
        context['thursday_timeslots'] = TimeSlot.objects.filter(start__range=(thursday, friday))
        context['friday_timeslots'] = TimeSlot.objects.filter(start__range=(friday, saturday))
        context['saturday_timeslots'] = TimeSlot.objects.filter(start__range=(saturday, sunday))
        context['sunday_timeslots'] = TimeSlot.objects.filter(start__range=(sunday, next_monday))

        return context