Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions src/backoffice/views/facilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/backoffice/views/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/facilities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
1 change: 1 addition & 0 deletions src/maps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading