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