From 7cb3770ad4c5b98cd6c8b17067bffd8e8636d062 Mon Sep 17 00:00:00 2001 From: "Rudy (zarya)" Date: Thu, 26 Jun 2025 17:26:24 +0200 Subject: [PATCH 1/3] Small fixes for handing uuid on features and map layers imports --- src/backoffice/views/facilities.py | 31 ++++++++++++++++++++++++------ src/backoffice/views/maps.py | 2 +- src/facilities/views.py | 2 +- src/maps/views.py | 1 + 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/backoffice/views/facilities.py b/src/backoffice/views/facilities.py index 0d6ad8705..3173d6457 100644 --- a/src/backoffice/views/facilities.py +++ b/src/backoffice/views/facilities.py @@ -96,12 +96,31 @@ def post(self, request, camp_slug, slug): else: errorCount += 1 continue - obj, created = Facility.objects.update_or_create( - name=props["name"], - description=description, - facility_type=facility_type, - location=geom, - ) + if "uuid" in props: + obj, created = Facility.objects.get_or_create( + uuid=props["uuid"], + facility_type=facility_type, + ) + obj.name = props["name"] + obj.description = description + obj.location = geom + obj.save() + elif "id" in feature: + obj, created = Facility.objects.get_or_create( + uuid=feature["id"], + facility_type=facility_type, + ) + obj.name = props["name"] + obj.description = description + obj.location = geom + obj.save() + else: + obj, created = Facility.objects.update_or_create( + name=props["name"], + description=description, + facility_type=facility_type, + location=geom, + ) if created: createdCount += 1 else: diff --git a/src/backoffice/views/maps.py b/src/backoffice/views/maps.py index 221f84181..1f177dfaf 100644 --- a/src/backoffice/views/maps.py +++ b/src/backoffice/views/maps.py @@ -113,7 +113,7 @@ def load_feature_collection(self, layer, geojson) -> None: # parse single feature geom = self.load_features(feature["geometry"]) self.create_feature_object( - feature_uuid=feature.get("id"), + feature_uuid=(feature["properties"]["uuid"] if "uuid" in feature["properties"] else feature.get("id")), props=feature["properties"], layer=layer, geom=geom, diff --git a/src/facilities/views.py b/src/facilities/views.py index 247b49fba..c05d30244 100644 --- a/src/facilities/views.py +++ b/src/facilities/views.py @@ -54,7 +54,7 @@ def dump_features(self) -> list[object]: for facility in Facility.objects.filter(facility_type=ft.pk): entry = { "type": "Feature", - "id": facility.pk, + "facility_id": facility.pk, "geometry": { "type": "Point", "coordinates": [facility.location.x, facility.location.y], diff --git a/src/maps/views.py b/src/maps/views.py index e534cbb95..dab8353a1 100644 --- a/src/maps/views.py +++ b/src/maps/views.py @@ -267,6 +267,7 @@ def get_context_data(self, **kwargs) -> dict: Feature.objects.filter(layer=self.layer.uuid), geometry_field="geom", fields=[ + "uuid", "name", "description", "color", From 557fdf97f03c44d81b8ee72ea99083adf6da526b Mon Sep 17 00:00:00 2001 From: "Rudy (zarya)" Date: Thu, 26 Jun 2025 18:16:37 +0200 Subject: [PATCH 2/3] Add comments --- src/backoffice/views/facilities.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/backoffice/views/facilities.py b/src/backoffice/views/facilities.py index 3173d6457..afe0e1a04 100644 --- a/src/backoffice/views/facilities.py +++ b/src/backoffice/views/facilities.py @@ -96,6 +96,7 @@ def post(self, request, camp_slug, slug): else: errorCount += 1 continue + # Check if UUID in props then create/update with UUID if "uuid" in props: obj, created = Facility.objects.get_or_create( uuid=props["uuid"], @@ -105,6 +106,7 @@ def post(self, request, camp_slug, slug): obj.description = description obj.location = geom obj.save() + # Check if id in feature then create/update with id as UUID elif "id" in feature: obj, created = Facility.objects.get_or_create( uuid=feature["id"], @@ -114,6 +116,7 @@ def post(self, request, camp_slug, slug): obj.description = description obj.location = geom obj.save() + # Create/Update feature without UUID else: obj, created = Facility.objects.update_or_create( name=props["name"], From e9c016d1d9d789a496a11f5f867f59fc99a47a9d Mon Sep 17 00:00:00 2001 From: Rudy <387694+zarya@users.noreply.github.com> Date: Thu, 26 Jun 2025 18:51:13 +0200 Subject: [PATCH 3/3] Update src/backoffice/views/maps.py Co-authored-by: Thomas Steen Rasmussen --- src/backoffice/views/maps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backoffice/views/maps.py b/src/backoffice/views/maps.py index 1f177dfaf..2a739df3b 100644 --- a/src/backoffice/views/maps.py +++ b/src/backoffice/views/maps.py @@ -113,7 +113,7 @@ def load_feature_collection(self, layer, geojson) -> None: # parse single feature geom = self.load_features(feature["geometry"]) self.create_feature_object( - feature_uuid=(feature["properties"]["uuid"] if "uuid" in feature["properties"] else feature.get("id")), + feature_uuid=(feature["properties"].get("uuid", feature.get("id"))), props=feature["properties"], layer=layer, geom=geom,