From 8882a972f310719bbba74b74d8bb134af8b9e3ba Mon Sep 17 00:00:00 2001
From: Richard Blechinger <hello@pretzelhands.com>
Date: Fri, 26 Nov 2021 13:05:01 +0100
Subject: [PATCH] Update default_playlist_id if set

---
 program/views.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/program/views.py b/program/views.py
index 6c19c532..22cb0789 100644
--- a/program/views.py
+++ b/program/views.py
@@ -471,9 +471,19 @@ class APIScheduleViewSet(viewsets.ModelViewSet):
         if 'schedule' not in request.data:
             return Response(status=status.HTTP_400_BAD_REQUEST)
 
+        # If we're updating the default playlist id
+        # TODO: If nothing else than default_playlist_id, automation_id or is_repetition changed -> just save and don't do anything
+        new_schedule = request.data.get('schedule')
+        if 'default_playlist_id' in new_schedule:
+            schedule = get_object_or_404(Schedule, pk=pk, show=show_pk)
+            schedule.default_playlist_id = int(new_schedule['default_playlist_id'])
+            schedule.save()
+
+            serializer = ScheduleSerializer(schedule)
+            return Response(serializer.data)
+
         # First update submit -> return projected timeslots and collisions
         if 'solutions' not in request.data:
-            # TODO: If nothing else than default_playlist_id, automation_id or is_repetition changed -> just save and don't do anything
             return Response(Schedule.make_conflicts(request.data['schedule'], pk, show_pk))
 
         # Otherwise try to resolve
-- 
GitLab