From e6da7e08797f5d01d6652f668b30ff07321506a6 Mon Sep 17 00:00:00 2001 From: Helge Jung <hej@c3pb.de> Date: Wed, 29 Dec 2021 02:19:15 +0100 Subject: [PATCH] ScheduleSource: add a lookup for skipped rooms anyway Skipped rooms should not be updated any more from the source, but new rooms should nevertheless be assigned to that room. --- src/core/models/schedules.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/core/models/schedules.py b/src/core/models/schedules.py index dc6faaad1..055da5341 100644 --- a/src/core/models/schedules.py +++ b/src/core/models/schedules.py @@ -187,7 +187,8 @@ class ScheduleSource(models.Model): if not new_mapping and mapping.local_id and mapping.local_id in expected_items: expected_items.remove(mapping.local_id) - return + # signal that we didn't actually load an item + return 'skipped' if new_mapping: try: @@ -219,6 +220,7 @@ class ScheduleSource(models.Model): # ... and delete the incomplete (wrong) mapping mapping.delete() + return 'error' else: # store new item's data @@ -229,7 +231,7 @@ class ScheduleSource(models.Model): 'source_id': item_source_id, 'local_id': str(mapping.local_id), }) - return + return 'added' # note that we've seen the existing room in the imported data if mapping.local_id in expected_items: @@ -247,7 +249,7 @@ class ScheduleSource(models.Model): 'source_id': item_source_id, 'local_id': str(mapping.local_id), }) - return + return 'deleted' # update data on existing room mapping.local_object.from_dict( @@ -265,6 +267,7 @@ class ScheduleSource(models.Model): 'source_id': item_source_id, 'local_id': str(mapping.local_id), }) + return 'seen' def load_data(self, data): assert isinstance(data, dict) @@ -288,7 +291,7 @@ class ScheduleSource(models.Model): # first, load the rooms (as they're needed for events) for r_id, r in data['rooms'].items(): try: - self._load_dataitem( + action = self._load_dataitem( activity=activity, item=r, item_source_id=r_id, @@ -299,6 +302,13 @@ class ScheduleSource(models.Model): 'allow_backend_roomtypes': False, }, ) + + if action == 'skipped': + # if the room has been skipped throw it into the mapping table anyway + r_mapping = self.mappings.get(mapping_type=ScheduleSourceMapping.MappingType.ROOM, source_id=r_id) + assert r_mapping.skip + rooms[r_id] = r_mapping.local_object + except Exception as err: activity.append({ 'action': 'error', -- GitLab