From 46ef27c3c69f3d1717fbfbef8764358018cec9f3 Mon Sep 17 00:00:00 2001 From: afonso pinto Date: Tue, 17 Dec 2024 14:12:35 +0000 Subject: [PATCH] SCKAN-373 fix: Add missing service file --- backend/composer/services/layers_service.py | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 backend/composer/services/layers_service.py diff --git a/backend/composer/services/layers_service.py b/backend/composer/services/layers_service.py new file mode 100644 index 00000000..be4c6a78 --- /dev/null +++ b/backend/composer/services/layers_service.py @@ -0,0 +1,28 @@ +from django.db import transaction + + + +def update_from_entities_on_deletion(connectivity_statement, deleted_entity_id): + """ + Updates the 'from_entities' for Layers that used the deleted entity. + Scoped to the given ConnectivityStatement. + """ + from composer.models import Destination, Via + + # Filter affected layers within the same ConnectivityStatement + affected_via_layers = Via.objects.filter( + connectivity_statement=connectivity_statement, + from_entities__id=deleted_entity_id + ) + + affected_destination_layers = Destination.objects.filter( + connectivity_statement=connectivity_statement, + from_entities__id=deleted_entity_id + ) + + # Update 'from_entities' by removing the deleted entity + for via in affected_via_layers: + via.from_entities.remove(deleted_entity_id) + + for destination in affected_destination_layers: + destination.from_entities.remove(deleted_entity_id) \ No newline at end of file