4 from django.views.generic.base import TemplateView
6 from emissions.models import Emission, Episode, Schedule
8 class ProgramView(TemplateView):
9 template_name = 'program.html'
11 def get_context_data(self, **kwargs):
12 context = super(ProgramView, self).get_context_data(**kwargs)
13 schedules = Schedule.objects.all().order_by('datetime')
16 days.append({'schedules': [x for x in schedules if x.is_on_weekday(day+1)],
17 'datetime': datetime.datetime(2007, 1, day+1)})
18 context['days'] = days
21 program = ProgramView.as_view()
29 def __init__(self, i, j):
34 def add_emission(self, emission):
35 self.emissions.append(emission)
37 def __unicode__(self):
39 return ', '.join([x.title for x in self.emissions])
43 def __eq__(self, other):
44 return (unicode(self) == unicode(other))
47 class Grid(TemplateView):
48 template_name = 'grid.html'
50 def get_context_data(self, **kwargs):
51 context = super(Grid, self).get_context_data(**kwargs)
52 schedules = Schedule.objects.all().order_by('datetime')
54 nb_lines = 2 * 24 # the cells are half hours
57 times = ['%02d:%02d' % (x/2, x%2*30) for x in range(nb_lines)]
59 times = times[2*5:] + times[:2*5]
61 nonstops = [[0, 2, 'Biodiversite'],
63 [5, 7.5, 'La Panique'],
64 [7.5, 10, 'Matin tranquille'],
65 [10, 12, 'Up Beat Tempo'],
66 [12, 13, 'L\'heure de pointe'],
67 [13, 16, 'Le Mange Disque'],
68 [16, 19, 'Hop Bop and co'],
69 [19, 22, 'Acouphene'],
70 [22, 24, 'Biodiversite']
73 for i in range(nb_lines):
76 grid[-1].append(TimeCell(i, j))
78 nonstop = [x for x in nonstops if i>=x[0]*2 and i<x[1]*2][0]
79 for time_cell in grid[-1]:
80 time_cell.nonstop = nonstop[2]
82 for schedule in Schedule.objects.all():
83 row_start = schedule.datetime.hour * 2 + \
84 int(math.ceil(schedule.datetime.minute / 30))
85 day_no = schedule.get_weekday()
87 for step in range(int(math.ceil(schedule.emission.duration / 30))):
88 if grid[row_start+step][day_no] is None:
89 print 'creating a time cell at', row_start+step, day_no
90 grid[row_start+step][day_no] = TimeCell()
91 grid[row_start+step][day_no].add_emission(schedule.emission)
95 grid = grid[2*5:] + grid[:2*5]
97 # merge adjacent cells
98 for i in range(nb_lines):
99 for j, cell in enumerate(grid[i]):
100 if grid[i][j] is None:
104 while grid[i][j+t] == cell:
110 grid[i] = [x for x in grid[i] if x is not None]
112 for i in range(nb_lines):
113 grid[i] = [x for x in grid[i] if x is not None]
114 for j, cell in enumerate(grid[i]):
115 if grid[i][j] is None:
120 same_cell_below = [(bj, x) for bj, x in enumerate(grid[i+cell.h])
121 if x == cell and x.y == cell.y and x.w == cell.w]
122 if not same_cell_below:
124 bj, same_cell_below = same_cell_below[0]
125 del grid[i+cell.h][bj]
130 context['grid'] = grid
131 context['times'] = times
132 context['weekdays'] = ['Lundi', 'Mardi', 'Mercredi', 'Jeudi',
133 'Vendredi', 'Samedi', 'Dimanche']
137 grid = Grid.as_view()
140 class Home(TemplateView):
141 template_name = 'home.html'
143 def get_context_data(self, **kwargs):
144 context = super(Home, self).get_context_data(**kwargs)
145 context['emissions'] = Emission.objects.all().order_by('?')[:5]
148 home = Home.as_view()
150 class Get(TemplateView):
151 template_name = 'get.html'
153 def get_context_data(self, **kwargs):
154 context = super(Get, self).get_context_data(**kwargs)
155 context['emissions'] = Emission.objects.all().order_by('title')
160 class Player(TemplateView):
161 template_name = 'player.html'
163 def get_context_data(self, **kwargs):
164 context = super(Player, self).get_context_data(**kwargs)
165 #context['emissions'] = Emission.objects.all().order_by('title')
168 player = Player.as_view()