diff --git a/src/backoffice/views/facilities.py b/src/backoffice/views/facilities.py index 0d6ad8705..afe0e1a04 100644 --- a/src/backoffice/views/facilities.py +++ b/src/backoffice/views/facilities.py @@ -96,12 +96,34 @@ 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, - ) + # Check if UUID in props then create/update with UUID + 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() + # 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"], + facility_type=facility_type, + ) + obj.name = props["name"] + obj.description = description + obj.location = geom + obj.save() + # Create/Update feature without UUID + 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..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.get("id"), + feature_uuid=(feature["properties"].get("uuid", 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",