From a2d896fc69889cb851bd5ea5f6a158880edf9d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Kl=C3=BCnder?= Date: Mon, 27 Nov 2023 22:07:40 +0100 Subject: [PATCH] ugly database fixes, needs improving --- src/c3nav/mapdata/fields.py | 3 +++ src/c3nav/mapdata/utils/geometry.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/c3nav/mapdata/fields.py b/src/c3nav/mapdata/fields.py index 9414dc0b..e0e32b66 100644 --- a/src/c3nav/mapdata/fields.py +++ b/src/c3nav/mapdata/fields.py @@ -113,6 +113,9 @@ class GeometryField(models.JSONField): def get_prep_value(self, value): if value is None: return None + if isinstance(value, dict): + # todo: this should also not be needed but whatever + value = shape(value) self._validate_geomtype(value, exception=TypeError) if value.is_empty: raise Exception('Cannot save empty geometry.') diff --git a/src/c3nav/mapdata/utils/geometry.py b/src/c3nav/mapdata/utils/geometry.py index a45209bb..1582d091 100644 --- a/src/c3nav/mapdata/utils/geometry.py +++ b/src/c3nav/mapdata/utils/geometry.py @@ -36,6 +36,9 @@ class WrappedGeometry(): wrapped_geojson = None def __init__(self, geojson): + if isinstance(geojson, str): + # todo: this should not be needed unless the database is fucked + geojson = json.loads(geojson) self.wrapped_geojson = geojson @cached_property