Skip to content

Commit bbe6d83

Browse files
authored
Small fixes for handing uuid on features and map layers imports (#1889)
1 parent e74a82b commit bbe6d83

4 files changed

Lines changed: 31 additions & 8 deletions

File tree

src/backoffice/views/facilities.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,34 @@ def post(self, request, camp_slug, slug):
9696
else:
9797
errorCount += 1
9898
continue
99-
obj, created = Facility.objects.update_or_create(
100-
name=props["name"],
101-
description=description,
102-
facility_type=facility_type,
103-
location=geom,
104-
)
99+
# Check if UUID in props then create/update with UUID
100+
if "uuid" in props:
101+
obj, created = Facility.objects.get_or_create(
102+
uuid=props["uuid"],
103+
facility_type=facility_type,
104+
)
105+
obj.name = props["name"]
106+
obj.description = description
107+
obj.location = geom
108+
obj.save()
109+
# Check if id in feature then create/update with id as UUID
110+
elif "id" in feature:
111+
obj, created = Facility.objects.get_or_create(
112+
uuid=feature["id"],
113+
facility_type=facility_type,
114+
)
115+
obj.name = props["name"]
116+
obj.description = description
117+
obj.location = geom
118+
obj.save()
119+
# Create/Update feature without UUID
120+
else:
121+
obj, created = Facility.objects.update_or_create(
122+
name=props["name"],
123+
description=description,
124+
facility_type=facility_type,
125+
location=geom,
126+
)
105127
if created:
106128
createdCount += 1
107129
else:

src/backoffice/views/maps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def load_feature_collection(self, layer, geojson) -> None:
113113
# parse single feature
114114
geom = self.load_features(feature["geometry"])
115115
self.create_feature_object(
116-
feature_uuid=feature.get("id"),
116+
feature_uuid=(feature["properties"].get("uuid", feature.get("id"))),
117117
props=feature["properties"],
118118
layer=layer,
119119
geom=geom,

src/facilities/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def dump_features(self) -> list[object]:
5454
for facility in Facility.objects.filter(facility_type=ft.pk):
5555
entry = {
5656
"type": "Feature",
57-
"id": facility.pk,
57+
"facility_id": facility.pk,
5858
"geometry": {
5959
"type": "Point",
6060
"coordinates": [facility.location.x, facility.location.y],

src/maps/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ def get_context_data(self, **kwargs) -> dict:
267267
Feature.objects.filter(layer=self.layer.uuid),
268268
geometry_field="geom",
269269
fields=[
270+
"uuid",
270271
"name",
271272
"description",
272273
"color",

0 commit comments

Comments
 (0)