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

fix: get correct fields from schedule object

parent 59a39a45
No related branches found
No related tags found
No related merge requests found
...@@ -1116,23 +1116,27 @@ class APIScheduleViewSet(viewsets.ModelViewSet): ...@@ -1116,23 +1116,27 @@ class APIScheduleViewSet(viewsets.ModelViewSet):
# only these fields can be updated without generating conflicts # only these fields can be updated without generating conflicts
allowed = {"default_playlist_id", "is_repetition", "last_date"} 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() schedule = self.get_object()
if default_playlist_id := request.data.get("default_playlist_id"): default_playlist_id = request.data.get("schedule").get("default_playlist_id")
if default_playlist_id == "": if default_playlist_id == "" or default_playlist_id is None:
# "clear" the default_playlist_id if the field has no value # "clear" the default_playlist_id if the field has no value
schedule.default_playlist_id = None schedule.default_playlist_id = None
else: else:
schedule.default_playlist_id = int(default_playlist_id) schedule.default_playlist_id = int(default_playlist_id)
if is_repetition := request.data.get("is_repetition"): is_repetition = request.data.get("schedule").get("is_repetition")
if is_repetition == "true" or is_repetition == "1": if is_repetition == "true" or is_repetition == "1":
schedule.is_repetition = True schedule.is_repetition = True
if is_repetition == "false" or is_repetition == "0": if is_repetition == "false" or is_repetition == "0":
schedule.is_repetition = False schedule.is_repetition = False
if last_date := request.data.get("last_date"): 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) last_date = date.fromisoformat(last_date)
if schedule.last_date is None or schedule.last_date > last_date: if schedule.last_date is None or schedule.last_date > last_date:
......
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