diff --git a/django/contrib/gis/forms/fields.py b/django/contrib/gis/forms/fields.py
index 59e7259..9b8b3cc 100644
|
a
|
b
|
class GeometryField(forms.Field):
|
| 47 | 47 | """ |
| 48 | 48 | if value in self.empty_values: |
| 49 | 49 | return None |
| 50 | | try: |
| 51 | | return GEOSGeometry(value) |
| 52 | | except (GEOSException, ValueError, TypeError): |
| 53 | | raise forms.ValidationError(self.error_messages['invalid_geom'], code='invalid_geom') |
| | 50 | |
| | 51 | if not isinstance(value, GEOSGeometry): |
| | 52 | try: |
| | 53 | value = GEOSGeometry(value) |
| | 54 | if not value.srid: |
| | 55 | value.srid = self.widget.map_srid |
| | 56 | except (GEOSException, ValueError, TypeError): |
| | 57 | raise forms.ValidationError(self.error_messages['invalid_geom'], code='invalid_geom') |
| | 58 | return value |
| 54 | 59 | |
| 55 | 60 | def clean(self, value): |
| 56 | 61 | """ |
| … |
… |
class GeometryField(forms.Field):
|
| 83 | 88 | def _has_changed(self, initial, data): |
| 84 | 89 | """ Compare geographic value of data with its initial value. """ |
| 85 | 90 | |
| 86 | | # Ensure we are dealing with a geographic object |
| 87 | | if isinstance(initial, six.string_types): |
| 88 | | try: |
| 89 | | initial = GEOSGeometry(initial) |
| 90 | | except (GEOSException, ValueError): |
| 91 | | initial = None |
| | 91 | try: |
| | 92 | data = self.to_python(data) |
| | 93 | initial = self.to_python(initial) |
| | 94 | except ValidationError: |
| | 95 | return True |
| 92 | 96 | |
| 93 | 97 | # Only do a geographic comparison if both values are available |
| 94 | 98 | if initial and data: |
| 95 | | data = fromstr(data) |
| 96 | 99 | data.transform(initial.srid) |
| 97 | 100 | # If the initial value was not added by the browser, the geometry |
| 98 | 101 | # provided may be slightly different, the first time it is saved. |
diff --git a/django/contrib/gis/forms/widgets.py b/django/contrib/gis/forms/widgets.py
index 0102ab6..b6f5f92 100644
|
a
|
b
|
class BaseGeometryWidget(Widget):
|
| 39 | 39 | |
| 40 | 40 | def deserialize(self, value): |
| 41 | 41 | try: |
| 42 | | return GEOSGeometry(value) |
| | 42 | return GEOSGeometry(value, self.map_srid) |
| 43 | 43 | except (GEOSException, ValueError) as err: |
| 44 | 44 | logger.error( |
| 45 | 45 | "Error creating geometry from value '%s' (%s)" % ( |
diff --git a/django/contrib/gis/tests/test_geoforms.py b/django/contrib/gis/tests/test_geoforms.py
index b4f6087..5d9f9f0 100644
|
a
|
b
|
class CustomGeometryWidgetTest(SimpleTestCase):
|
| 269 | 269 | # Force deserialize use due to a string value |
| 270 | 270 | self.assertIn(escape(point.json), widget.render('p', point.json)) |
| 271 | 271 | self.assertEqual(widget.deserialize_called, 1) |
| | 272 | |
| | 273 | form = PointForm(data={'p': point.json}) |
| | 274 | self.assertTrue(form.is_valid()) |
| | 275 | # Ensure that resulting geometry has srid set |
| | 276 | self.assertEqual(form.cleaned_data['p'].srid, 4326) |