Skip to content
Snippets Groups Projects
Commit 71be8be3 authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt :koala:
Browse files

fix: generate stable ids for program entries

Up until now the id of the first and last program entry was based on the
filtered range. Instead, we want these to be based on the first timeslot
that was scheduled before/after the specified range. This way we ensure
that the ids of these entries are stable as long as the schedule doesn’t
change.
parent 715d2cc6
No related branches found
No related tags found
1 merge request!57Incorporate feedback for virtual timeslots
...@@ -765,12 +765,25 @@ def generate_program_entries( ...@@ -765,12 +765,25 @@ def generate_program_entries(
# show. We can only create these program entries if a fallback show has been specified. # show. We can only create these program entries if a fallback show has been specified.
fallback_show = get_fallback_show(raise_exceptions=True) fallback_show = get_fallback_show(raise_exceptions=True)
entry_start = start # Shift the range start/end to the closest scheduled timeslots around the specified range.
# This ensures that we generate stable ids for entries.
# We first check if the timeslots in our queryset might already start/end before/after the
# specified range, because we potentially include them according to the filter above.
first_ts_before_start = timeslots.first()
if not first_ts_before_start or first_ts_before_start.start > start:
first_ts_before_start = queryset.filter(end__lte=start).last()
first_ts_after_end = timeslots.last()
if not first_ts_after_end or first_ts_after_end.end < end:
first_ts_after_end = queryset.filter(start__gte=end).first()
range_start = first_ts_before_start.end if first_ts_before_start else start
range_end = first_ts_after_end.start if first_ts_after_end else end
entry_start = range_start
timeslot: TimeSlot timeslot: TimeSlot
for timeslot in timeslots: for timeslot in timeslots:
if timeslot.start > entry_start: if timeslot.start > entry_start:
yield create_entry(entry_start, timeslot.start, fallback_show) yield create_entry(entry_start, timeslot.start, fallback_show)
yield create_timeslot_entry(timeslot) yield create_timeslot_entry(timeslot)
entry_start = timeslot.end entry_start = timeslot.end
if entry_start < end: if entry_start < range_end:
yield create_entry(entry_start, end, fallback_show) yield create_entry(entry_start, range_end, fallback_show)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment