|
@@ -41,10 +41,15 @@ class GeometryField(forms.Field):
|
|
|
"""
|
|
|
if value in self.empty_values:
|
|
|
return None
|
|
|
- try:
|
|
|
- return GEOSGeometry(value)
|
|
|
- except (GEOSException, ValueError, TypeError):
|
|
|
- raise forms.ValidationError(self.error_messages['invalid_geom'], code='invalid_geom')
|
|
|
+
|
|
|
+ if not isinstance(value, GEOSGeometry):
|
|
|
+ try:
|
|
|
+ value = GEOSGeometry(value)
|
|
|
+ if not value.srid:
|
|
|
+ value.srid = self.widget.map_srid
|
|
|
+ except (GEOSException, ValueError, TypeError):
|
|
|
+ raise forms.ValidationError(self.error_messages['invalid_geom'], code='invalid_geom')
|
|
|
+ return value
|
|
|
|
|
|
def clean(self, value):
|
|
|
"""
|
|
@@ -77,16 +82,14 @@ class GeometryField(forms.Field):
|
|
|
def _has_changed(self, initial, data):
|
|
|
""" Compare geographic value of data with its initial value. """
|
|
|
|
|
|
-
|
|
|
- if isinstance(initial, six.string_types):
|
|
|
- try:
|
|
|
- initial = GEOSGeometry(initial)
|
|
|
- except (GEOSException, ValueError):
|
|
|
- initial = None
|
|
|
+ try:
|
|
|
+ data = self.to_python(data)
|
|
|
+ initial = self.to_python(initial)
|
|
|
+ except ValidationError:
|
|
|
+ return True
|
|
|
|
|
|
|
|
|
if initial and data:
|
|
|
- data = fromstr(data)
|
|
|
data.transform(initial.srid)
|
|
|
|
|
|
|