diff --git a/program/services.py b/program/services.py index 87693930e93d08256d2b2c79e48c0ca467ea01a9..255d1b4513527c18c024a7829aac93a548870cef 100644 --- a/program/services.py +++ b/program/services.py @@ -700,6 +700,17 @@ def generate_conflicts(timeslots: list[TimeSlot]) -> Conflicts: return conflicts +def get_fallback_show(raise_exceptions: bool = False): + radio_settings: RadioSettings | None = RadioSettings.objects.first() + fallback_show = radio_settings.fallback_show if radio_settings is not None else None + if raise_exceptions and fallback_show is None: + raise ConfigurationError( + "Radio settings must define a fallback show if include_virtual is True.", + code="no-fallback-show-defined", + ) + return fallback_show + + def generate_program_entries( queryset: QuerySet[TimeSlot], *, @@ -743,13 +754,9 @@ def generate_program_entries( yield from (create_timeslot_entry(timeslot) for timeslot in queryset) return - radio_settings: RadioSettings | None = RadioSettings.objects.first() - fallback_show = radio_settings.fallback_show if radio_settings is not None else None - if fallback_show is None: - raise ConfigurationError( - "Radio settings must define a fallback show if include_virtual is True.", - code="no-fallback-show-defined", - ) + # Program entries that are not based on scheduled timeslots are generated using the fallback + # show. We can only create these program entries if a fallback show has been specified. + fallback_show = get_fallback_show(raise_exceptions=True) entry_start = start timeslot: TimeSlot