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

refactor: use the typed dicts explicitly

parent 5bd89e8a
No related branches found
No related tags found
No related merge requests found
Pipeline #8294 failed
......@@ -53,9 +53,11 @@ from program.models import (
)
from program.typing import (
Logo,
MicroProgram,
NestedEpisode,
NestedSchedule,
NestedShow,
ProgramFallback,
RadioCBASettings,
RadioImageRequirementsSettings,
RadioPlayoutSettings,
......@@ -1197,12 +1199,12 @@ class RadioSettingsSerializer(serializers.ModelSerializer):
def get_cba(self, obj) -> RadioCBASettings:
if self.context.get("request").user.is_authenticated:
return {
"api_key": obj.cba_api_key,
"domains": obj.cba_domains,
}
return RadioCBASettings(
api_key=obj.cba_api_key,
domains=obj.cba_domains,
)
else:
return {"domains": obj.cba_domains}
return RadioCBASettings(domains=obj.cba_domains)
@staticmethod
def get_image_requirements(obj) -> RadioImageRequirementsSettings:
......@@ -1252,36 +1254,38 @@ class RadioSettingsSerializer(serializers.ModelSerializer):
@staticmethod
def get_program(obj) -> RadioProgramSettings:
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" if obj.fallback_default_pool else "",
},
}
return RadioProgramSettings(
micro=MicroProgram(show_id=obj.micro_show.id if obj.micro_show else None),
fallback=ProgramFallback(
show_id=obj.fallback_show.id if obj.fallback_show else None,
default_pool="fallback" if obj.fallback_default_pool else "",
),
)
@staticmethod
def get_playout(obj) -> RadioPlayoutSettings:
return {
"line_in_channels": obj.line_in_channels,
"pools": obj.pools,
}
return RadioPlayoutSettings(
line_in_channels=obj.line_in_channels,
pools=obj.pools,
)
@staticmethod
def get_station(obj) -> RadioStationSettings:
return {
"name": obj.station_name,
"logo": (
Logo(
url=f"{settings.SITE_URL}{obj.station_logo.url}",
height=obj.station_logo.height,
width=obj.station_logo.width,
)
if obj.station_logo
else None
),
"website": obj.station_website,
}
logo = (
Logo(
url=f"{settings.SITE_URL}{obj.station_logo.url}",
height=obj.station_logo.height,
width=obj.station_logo.width,
)
if obj.station_logo
else None
)
return RadioStationSettings(
name=obj.station_name,
logo=logo,
website=obj.station_website,
)
# done this way to get the schema annotations for datetime right
......
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