From 465d06ac443c804a38663ca2472c97c4a2df3308 Mon Sep 17 00:00:00 2001 From: Ernesto Rico Schmidt <ernesto@helsinki.at> Date: Wed, 11 Sep 2024 15:47:49 -0400 Subject: [PATCH] fix: get correct fields from schedule object --- program/views.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/program/views.py b/program/views.py index 4d54e59b..fa41eb85 100644 --- a/program/views.py +++ b/program/views.py @@ -1116,23 +1116,27 @@ class APIScheduleViewSet(viewsets.ModelViewSet): # only these fields can be updated without generating conflicts allowed = {"default_playlist_id", "is_repetition", "last_date"} - if set(request.data["schedule"].keys()).issubset(allowed): + if set(request.data.get("schedule").keys()).issubset(allowed): schedule = self.get_object() - if default_playlist_id := request.data.get("default_playlist_id"): - if default_playlist_id == "": - # "clear" the default_playlist_id if the field has no value - schedule.default_playlist_id = None - else: - schedule.default_playlist_id = int(default_playlist_id) - - if is_repetition := request.data.get("is_repetition"): - if is_repetition == "true" or is_repetition == "1": - schedule.is_repetition = True - if is_repetition == "false" or is_repetition == "0": - schedule.is_repetition = False - - if last_date := request.data.get("last_date"): + default_playlist_id = request.data.get("schedule").get("default_playlist_id") + if default_playlist_id == "" or default_playlist_id is None: + # "clear" the default_playlist_id if the field has no value + schedule.default_playlist_id = None + else: + schedule.default_playlist_id = int(default_playlist_id) + + is_repetition = request.data.get("schedule").get("is_repetition") + if is_repetition == "true" or is_repetition == "1": + schedule.is_repetition = True + if is_repetition == "false" or is_repetition == "0": + schedule.is_repetition = False + + last_date = request.data.get("schedule").get("last_date") + if last_date == "" or last_date is None: + # "clear" the last_date if the field has no value + schedule.last_date = None + else: last_date = date.fromisoformat(last_date) if schedule.last_date is None or schedule.last_date > last_date: -- GitLab