From d4acb1cbd916334b9ac216532b42e9feb76724d4 Mon Sep 17 00:00:00 2001
From: Robert Sparks <rjsparks@nostrum.com>
Date: Mon, 12 Jun 2017 20:01:47 +0000
Subject: [PATCH] Workaround an issue with the schedule editor by ensuring no
 sessions remain scheduled in a room whose purpose has changed to something
 other than holding sessions (such as becoming unavailable). Commit ready for
 merge.  - Legacy-Id: 13586

---
 ietf/meeting/ajax.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/ietf/meeting/ajax.py b/ietf/meeting/ajax.py
index 32e97dbd1..2c6e0e199 100644
--- a/ietf/meeting/ajax.py
+++ b/ietf/meeting/ajax.py
@@ -205,6 +205,19 @@ def timeslot_updslot(request, meeting, slotid):
 
     slot.save()
 
+    # WORKAROUND: Right now, if there are sessions scheduled in this timeslot
+    # when it is marked unavailable (or any other value besides "session") they
+    # become unreachable from the editing screen. The session is listed in the
+    # "unscheduled" block incorrectly, and drag-dropping it onto the a new
+    # timeslot produces erroneous results. To avoid this, we will silently
+    # unschedule any sessions in the timeslot that has just been made
+    # unavailable.
+
+    if slot.type_id != 'session':
+        slot.sessionassignments.all().delete()
+
+    # ENDWORKAROUND
+
     # need to return the new object.
     dict1 = slot.json_dict(request.build_absolute_uri('/'))
     dict1['message'] = 'valid'