Skip to content

Commit

Permalink
maps: fix GeoJsonPointMixin with dict as input
Browse files Browse the repository at this point in the history
  • Loading branch information
m4ra authored and goapunk committed Feb 25, 2025
1 parent 82b2455 commit 87561ed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion adhocracy4/maps/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ def unpack_geojson(self, data):
if self.Meta.geo_field and self.Meta.geo_field in data:
geo_field = data[self.Meta.geo_field]
if geo_field:
point = json.loads(geo_field)
if isinstance(geo_field, dict):
point = geo_field
else:
point = json.loads(geo_field)
data = data.copy()

if "geometry" in point:
Expand Down
4 changes: 4 additions & 0 deletions changelog/_0004.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### fixed

- GeoJsonPointMixin can accept also dict payload

11 changes: 11 additions & 0 deletions tests/maps/test_map_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ def test_valid_point_correctly_serialized_to_internal_value(geojson_point, geos_
assert "street_name" not in data


@pytest.mark.django_db
def test_valid_point_as_dict_correctly_serialized_to_internal_value(
geojson_point, geos_point
):
del geojson_point["properties"]
serializer = TestPointSerializer()
data = serializer.to_internal_value(data={"point": geojson_point})
assert data["point"].equals(geos_point)
assert "street_name" not in data


@pytest.mark.django_db
def test_valid_point_with_properties_to_internal_value(geojson_point, geos_point):
serializer = TestPointSerializer()
Expand Down

0 comments on commit 87561ed

Please sign in to comment.