diff --git a/program/views.py b/program/views.py index 4d54e59b042decdd4dd4635ff1684c05d8bdcb84..fa41eb850f9712b9e4a7aeefc91e60886701044c 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: