From d0ba9abc761de6e8a7d27c36b637f81d385d7f34 Mon Sep 17 00:00:00 2001
From: Ernesto Rico Schmidt <ernesto@helsinki.at>
Date: Mon, 24 Jun 2024 17:40:41 -0400
Subject: [PATCH] feat: update Radio settings serializer

---
 program/serializers.py | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/program/serializers.py b/program/serializers.py
index 2d3b67d7..1f38d1f0 100644
--- a/program/serializers.py
+++ b/program/serializers.py
@@ -1217,7 +1217,7 @@ class RadioStationSettings(TypedDict):
 
 
 class ImageFrame(TypedDict):
-    aspect_ratio: tuple[int, int]
+    aspect_ratio: tuple[int, int] | tuple[float, float]
     shape: Literal["rect", "round"]
 
 
@@ -1266,18 +1266,21 @@ class RadioSettingsSerializer(serializers.ModelSerializer):
 
     @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."""
+        def get_aspect_ratio(field) -> tuple[int, int] | tuple[float, float]:
+            """return the tuple of ints or floats representing the aspect ratio of the image."""
 
             values = field.split(":")
 
-            return int(values[0]), int(values[1])
+            try:
+                return int(values[0]), int(values[1])
+            except ValueError:
+                return float(values[0]), float(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),
+            "host.image": get_aspect_ratio(obj.host_image_aspect_ratio),
+            "note.image": get_aspect_ratio(obj.note_image_aspect_ratio),
+            "show.image": get_aspect_ratio(obj.show_image_aspect_ratio),
+            "show.logo": get_aspect_ratio(obj.show_logo_aspect_ratio),
         }
 
         return {
-- 
GitLab