diff options
| author | Claude Paroz <claude@2xlibre.net> | 2018-02-06 11:51:41 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-04-02 10:20:00 -0400 |
| commit | 2a2ed0e70a93bfd1a3d41af40870fe963dc2687d (patch) | |
| tree | a23d1526aab1324798e431f78d9327c734a66a92 /django/contrib/gis/forms/widgets.py | |
| parent | 09c6d0146178d83b6bd6cc8bb4162a5ae7c1c5f5 (diff) | |
Fixed #29116 -- Fixed OpenLayersWidget deserialization ignoring the widget map's SRID.
Regression in 6ecccad711b52f9273b1acb07a57d3f806e93928.
Diffstat (limited to 'django/contrib/gis/forms/widgets.py')
| -rw-r--r-- | django/contrib/gis/forms/widgets.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/django/contrib/gis/forms/widgets.py b/django/contrib/gis/forms/widgets.py index 0ffe2ced77..cd9bff9f68 100644 --- a/django/contrib/gis/forms/widgets.py +++ b/django/contrib/gis/forms/widgets.py @@ -2,6 +2,7 @@ import logging from django.conf import settings from django.contrib.gis import gdal +from django.contrib.gis.geometry import json_regex from django.contrib.gis.geos import GEOSException, GEOSGeometry from django.forms.widgets import Widget from django.utils import translation @@ -36,7 +37,7 @@ class BaseGeometryWidget(Widget): def deserialize(self, value): try: return GEOSGeometry(value) - except (GEOSException, ValueError) as err: + except (GEOSException, ValueError, TypeError) as err: logger.error("Error creating geometry from value '%s' (%s)", value, err) return None @@ -91,6 +92,13 @@ class OpenLayersWidget(BaseGeometryWidget): def serialize(self, value): return value.json if value else '' + def deserialize(self, value): + geom = super().deserialize(value) + # GeoJSON assumes WGS84 (4326). Use the map's SRID instead. + if geom and json_regex.match(value) and self.map_srid != 4326: + geom.srid = self.map_srid + return geom + class OSMWidget(OpenLayersWidget): """ |
