1
0
mirror of https://github.com/django/django.git synced 2025-10-27 07:36:08 +00:00

Fixed #21496 -- Fixed crash when GeometryField uses TextInput

Thanks Rhett Garber for the report and initial patch.
This commit is contained in:
Claude Paroz
2013-11-23 10:53:09 +01:00
parent c8b637d88e
commit 34b8a38558
3 changed files with 28 additions and 11 deletions

View File

@@ -44,10 +44,16 @@ class GeometryField(forms.Field):
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')
# Try to set the srid
if not value.srid:
try:
value.srid = self.widget.map_srid
except AttributeError:
if self.srid:
value.srid = self.srid
return value
def clean(self, value):
@@ -66,15 +72,12 @@ class GeometryField(forms.Field):
raise forms.ValidationError(self.error_messages['invalid_geom_type'], code='invalid_geom_type')
# Transforming the geometry if the SRID was set.
if self.srid:
if not geom.srid:
# Should match that of the field if not given.
geom.srid = self.srid
elif self.srid != -1 and self.srid != geom.srid:
try:
geom.transform(self.srid)
except GEOSException:
raise forms.ValidationError(self.error_messages['transform_error'], code='transform_error')
if self.srid and self.srid != -1 and self.srid != geom.srid:
try:
geom.transform(self.srid)
except GEOSException:
raise forms.ValidationError(
self.error_messages['transform_error'], code='transform_error')
return geom