diff --git a/program/services.py b/program/services.py index 1d01adbff6398f056dbdb256201350c9f9501aa9..4b0413c34a3c6490684f54ed0fe0e69bec261de6 100644 --- a/program/services.py +++ b/program/services.py @@ -24,7 +24,7 @@ from typing import Literal, TypedDict from dateutil.relativedelta import relativedelta from dateutil.rrule import rrule -from rest_framework.exceptions import ValidationError +from rest_framework.exceptions import NotFound, ValidationError from django.conf import settings from django.core.exceptions import ObjectDoesNotExist @@ -816,13 +816,16 @@ def make_timeslot_entry(*, timeslot: TimeSlot) -> TimeslotEntry: 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`.""" - return { - "end": gap_end.strftime("%Y-%m-%dT%H:%M:%S %z"), - "is_virtual": True, - "show_id": RadioSettings.objects.first().fallback_show.id, - "show_name": RadioSettings.objects.first().fallback_default_pool, - "start": gap_start.strftime("%Y-%m-%dT%H:%M:%S %z"), - } + 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"), + } + else: + raise NotFound("Radio settings with fallbacks not found.") def get_timerange_timeslot_entries(