diff --git a/program/serializers.py b/program/serializers.py index 4a13478fcb221312eb8ce40fa6ee119e449c48f3..b624ad630397f8d613bd72faff7b72838e4360fc 100644 --- a/program/serializers.py +++ b/program/serializers.py @@ -19,7 +19,7 @@ # import re -from typing import NotRequired, TypedDict +from typing import Literal, NotRequired, TypedDict from drf_jsonschema_serializer import JSONSchemaField from rest_framework import serializers @@ -1094,12 +1094,27 @@ class RadioCBASettings(TypedDict): domains: list[str] +class ProgrammeFallback(TypedDict): + default_pool: Literal["fallback"] | None + show_id: int | None + + +class MicroProgramme(TypedDict): + show_id: int | None + + class RadioProgrammeSettings(TypedDict): - fallback_show_id: int | None + fallback: ProgrammeFallback + micro: MicroProgramme + + +class PlayoutPools(TypedDict): + fallback: str | None class RadioPlayoutSettings(TypedDict): line_in_channels: dict[str, str] + pools: PlayoutPools class RadioStationSettings(TypedDict): @@ -1108,15 +1123,43 @@ class RadioStationSettings(TypedDict): website: str +class ImageFrame(TypedDict): + aspect_ratio: tuple[int, int] + shape: Literal["rect", "round"] + + +class ImageRequirements(TypedDict): + frame: ImageFrame + + +# done this way, because the keys have dots (".") +RadioImageRequirementsSettings = TypedDict( + "RadioImageRequirementsSettings", + { + "host.image": ImageRequirements, + "note.image": ImageRequirements, + "show.image": ImageRequirements, + "show.logo": ImageRequirements, + }, +) + + class RadioSettingsSerializer(serializers.ModelSerializer): cba = serializers.SerializerMethodField() + image_requirements = serializers.SerializerMethodField() playout = serializers.SerializerMethodField() programme = serializers.SerializerMethodField() station = serializers.SerializerMethodField() class Meta: - read_only_fields = ("id", "cba", "playout", "programme", "station") - fields = read_only_fields + fields = read_only_fields = ( + "id", + "cba", + "image_requirements", + "playout", + "programme", + "station", + ) model = RadioSettings def get_cba(self, obj) -> RadioCBASettings: @@ -1128,13 +1171,67 @@ class RadioSettingsSerializer(serializers.ModelSerializer): else: return {"domains": obj.cba_domains} + @staticmethod + def get_image_requirements(obj) -> RadioImageRequirementsSettings: + def get_aspect_ration(field) -> tuple[int, int]: + """return the tuple of ints representing the aspect ratio of the image.""" + + values = field.split(":") + + return int(values[0]), int(values[1]) + + aspect_ratios = { + "host.image": get_aspect_ration(obj.host_image_aspect_ratio), + "note.image": get_aspect_ration(obj.note_image_aspect_ratio), + "show.image": get_aspect_ration(obj.show_image_aspect_ratio), + "show.logo": get_aspect_ration(obj.show_logo_aspect_ratio), + } + + return { + "host.image": { + "frame": { + "aspect_ratio": aspect_ratios["host.image"], + "shape": obj.host_image_shape, + } + }, + "note.image": { + "frame": { + "aspect_ratio": aspect_ratios["note.image"], + "shape": obj.host_image_shape, + } + }, + "show.image": { + "frame": { + "aspect_ratio": aspect_ratios["show.image"], + "shape": obj.host_image_shape, + } + }, + "show.logo": { + "frame": { + "aspect_ratio": aspect_ratios["show.logo"], + "shape": obj.host_image_shape, + } + }, + } + @staticmethod def get_programme(obj) -> RadioProgrammeSettings: - return {"fallback_show_id": obj.fallback_show.id if obj.fallback_show else None} + return { + "micro": {"show_id": obj.micro_show.id if obj.micro_show else None}, + "fallback": { + "show_id": obj.fallback_show.id if obj.fallback_show else None, + "default_pool": "fallback", + }, + } @staticmethod def get_playout(obj) -> RadioPlayoutSettings: - return {"line_in_channels": obj.line_in_channels} + return { + "line_in_channels": obj.line_in_channels, + "pools": { + "fallback": obj.fallback_default_pool, + }, + } @staticmethod def get_station(obj) -> RadioStationSettings: