Commit 6bb795de authored by fred's avatar fred

grid: do not put the same emission twice in the same cell

parent b099ddac
......@@ -192,7 +192,33 @@ class Grid(TemplateView):
# start grid after the night programs
grid = grid[2*Schedule.DAY_HOUR_START:] + grid[:2*Schedule.DAY_HOUR_START]
# merge adjacent cells
# look for the case where the same emission has different schedules for
# the same time cell, for example if it lasts one hour the first week,
# and two hours the third week.
for i in range(nb_lines):
grid[i] = [x for x in grid[i] if x is not None]
for j, cell in enumerate(grid[i]):
if grid[i][j] is None:
continue
if len(grid[i][j].schedules) > 1:
time_cell_emissions = {}
for schedule in grid[i][j].schedules:
if not schedule.emission.id in time_cell_emissions:
time_cell_emissions[schedule.emission.id] = []
time_cell_emissions[schedule.emission.id].append(schedule)
for schedule_list in time_cell_emissions.values():
if len(schedule_list) == 1:
continue
# here it is, same cell, same emission, several
# schedules
schedule_list.sort(lambda x,y: -cmp(x.get_duration(), y.get_duration()))
for schedule in schedule_list[1:]:
grid[i][j].schedules.remove(schedule)
end_time = schedule.datetime + timedelta(minutes=schedule.get_duration())
schedule_list[0].time_label_extra = ', -%02d:%02d %s' % (
end_time.hour, end_time.minute, schedule.weeks_string)
# merge adjacent
# 1st thing is to merge cells on the same line, this will mostly catch
# consecutive nonstop cells
......
......@@ -45,6 +45,9 @@
{% if schedule.weeks_string %}
<span>{{ schedule.weeks_string }}</span>
{% endif %}
{% if schedule.time_label_extra %}
<span>{{ schedule.time_label_extra }}</span>
{% endif %}
<span>)</span>
{% endspaceless %}
{% endif %}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment