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

refactor: extract TypeDict annotations into typing module

parent 82f776f5
No related branches found
No related tags found
No related merge requests found
......@@ -19,7 +19,6 @@
#
import re
from typing import Literal, NotRequired, TypedDict
from drf_jsonschema_serializer import JSONSchemaField
from rest_framework import serializers
......@@ -52,7 +51,17 @@ from program.models import (
Type,
UserProfile,
)
from program.typing import NestedEpisode, NestedSchedule, NestedShow
from program.typing import (
Logo,
NestedEpisode,
NestedSchedule,
NestedShow,
RadioCBASettings,
RadioImageRequirementsSettings,
RadioPlayoutSettings,
RadioProgramSettings,
RadioStationSettings,
)
from program.utils import update_links
SOLUTION_CHOICES = {
......@@ -278,12 +287,6 @@ class PPOIField(serializers.CharField):
return f"{left}x{top}"
class Thumbnail(TypedDict):
width: float
height: float
url: str
class ImageSerializer(serializers.ModelSerializer):
license_id = serializers.PrimaryKeyRelatedField(
allow_null=True,
......@@ -1174,67 +1177,6 @@ class NoteSerializer(serializers.ModelSerializer):
return instance
class RadioCBASettings(TypedDict):
api_key: NotRequired[str]
domains: list[str]
class ProgramFallback(TypedDict):
default_pool: str
show_id: int | None
class MicroProgram(TypedDict):
show_id: int | None
class RadioProgramSettings(TypedDict):
fallback: ProgramFallback
micro: MicroProgram
class PlayoutPools(TypedDict):
fallback: str | None
class RadioPlayoutSettings(TypedDict):
line_in_channels: dict[str, str]
pools: PlayoutPools
class Logo(TypedDict):
url: str
height: int
width: int
class RadioStationSettings(TypedDict):
name: str
logo: Logo | None
website: str
class ImageFrame(TypedDict):
aspect_ratio: tuple[int, int] | tuple[float, float]
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()
......
from typing import TypedDict
from typing import Literal, NotRequired, TypedDict
class NestedTimeslot(TypedDict):
......@@ -38,3 +38,70 @@ class TimerangeEntry(TypedDict):
schedule: NestedSchedule | None
show: NestedShow
timeslot: NestedTimeslot
class Thumbnail(TypedDict):
width: float
height: float
url: str
class RadioCBASettings(TypedDict):
api_key: NotRequired[str]
domains: list[str]
class ProgramFallback(TypedDict):
default_pool: str
show_id: int | None
class MicroProgram(TypedDict):
show_id: int | None
class RadioProgramSettings(TypedDict):
fallback: ProgramFallback
micro: MicroProgram
class PlayoutPools(TypedDict):
fallback: str | None
class RadioPlayoutSettings(TypedDict):
line_in_channels: dict[str, str]
pools: PlayoutPools
class Logo(TypedDict):
url: str
height: int
width: int
class RadioStationSettings(TypedDict):
name: str
logo: Logo | None
website: str
class ImageFrame(TypedDict):
aspect_ratio: tuple[int, int] | tuple[float, float]
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,
},
)
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