Skip to content
Snippets Groups Projects
Verified Commit c33fa67c authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

refactor: return ScheduleEntry, TimeslotEntry & VirtualTimeslotEntry directly

parent 8169b203
No related branches found
No related tags found
No related merge requests found
......@@ -782,13 +782,13 @@ def generate_conflicts(timeslots: list[TimeSlot]) -> Conflicts:
def make_schedule_entry(*, timeslot_entry: TimeslotEntry) -> ScheduleEntry:
"""returns a schedule entry for the given timeslot entry."""
return {
"end": timeslot_entry["end"],
"show_id": timeslot_entry["show_id"],
"is_virtual": timeslot_entry["is_virtual"],
"start": timeslot_entry["start"],
"show_name": timeslot_entry["show_name"],
}
return ScheduleEntry(
end=timeslot_entry["end"],
show_id=timeslot_entry["show_id"],
is_virtual=timeslot_entry["is_virtual"],
start=timeslot_entry["start"],
show_name=timeslot_entry["show_name"],
)
def make_timeslot_entry(*, timeslot: TimeSlot) -> TimeslotEntry:
......@@ -797,33 +797,33 @@ def make_timeslot_entry(*, timeslot: TimeSlot) -> TimeslotEntry:
schedule = timeslot.schedule
show = timeslot.schedule.show
return {
"end": timeslot.end.strftime("%Y-%m-%dT%H:%M:%S%z"),
"is_virtual": False,
"playlist_id": timeslot.playlist_id,
return TimeslotEntry(
end=timeslot.end.strftime("%Y-%m-%dT%H:%M:%S%z"),
is_virtual=False,
playlist_id=timeslot.playlist_id,
# 'timeslot.repetition_of` is a foreign key that can be null
"repetition_of_id": timeslot.repetition_of.id if timeslot.repetition_of else None,
"schedule_default_playlist_id": schedule.default_playlist_id,
"schedule_id": schedule.id,
"show_default_playlist_id": show.default_playlist_id,
"show_id": show.id,
"show_name": show.name,
"start": timeslot.start.strftime("%Y-%m-%dT%H:%M:%S%z"),
"timeslot_id": timeslot.id,
}
repetition_of_id=timeslot.repetition_of.id if timeslot.repetition_of else None,
schedule_default_playlist_id=schedule.default_playlist_id,
schedule_id=schedule.id,
show_default_playlist_id=show.default_playlist_id,
show_id=show.id,
show_name=show.name,
start=timeslot.start.strftime("%Y-%m-%dT%H:%M:%S%z"),
timeslot_id=timeslot.id,
)
def make_virtual_timeslot_entry(*, gap_start: datetime, gap_end: datetime) -> VirtualTimeslotEntry:
"""returns a virtual timeslot entry to fill the gap in between `gap_start` and `gap_end`."""
if radio_settings := RadioSettings.objects.first():
return {
"end": gap_end.strftime("%Y-%m-%dT%H:%M:%S%z"),
"is_virtual": True,
"show_id": radio_settings.fallback_show.id,
"show_name": radio_settings.fallback_default_pool,
"start": gap_start.strftime("%Y-%m-%dT%H:%M:%S%z"),
}
return VirtualTimeslotEntry(
end=gap_end.strftime("%Y-%m-%dT%H:%M:%S%z"),
is_virtual=True,
show_id=radio_settings.fallback_show.id,
show_name=radio_settings.fallback_default_pool,
start=gap_start.strftime("%Y-%m-%dT%H:%M:%S%z"),
)
else:
raise NotFound(
detail=_("Radio settings with fallbacks not found."), code="radio_settings-not_found"
......
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