views.py 942 Bytes
Newer Older
fred's avatar
fred committed
1
2
import datetime

fred's avatar
fred committed
3
4
from django.views.generic.base import TemplateView

fred's avatar
fred committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from emissions.models import Emission, Schedule

class ProgramView(TemplateView):
    template_name = 'program.html'

    def get_context_data(self, **kwargs):
        context = super(ProgramView, self).get_context_data(**kwargs)
        schedules = Schedule.objects.all().order_by('datetime')
        days = []
        for day in range(7):
            days.append({'schedules': [x for x in schedules if x.is_on_weekday(day+1)],
                         'datetime': datetime.datetime(2007, 1, day+1)})
        context['days'] = days
        return context

program = ProgramView.as_view()

22

fred's avatar
fred committed
23
24
25
class Home(TemplateView):
    template_name = 'home.html'

26
27
28
29
30
    def get_context_data(self, **kwargs):
        context = super(Home, self).get_context_data(**kwargs)
        context['emissions'] = Emission.objects.all().order_by('?')[:5]
        return context

fred's avatar
fred committed
31
home = Home.as_view()