Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

gis: Fixed #6357, and added a validator to `WKTField`.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8da13e60c2b0df68f41897e1fca21ae370a49318 1 parent 3dd6b42
@jbronn jbronn authored
Showing with 19 additions and 4 deletions.
  1. +19 −4 django/contrib/gis/oldforms/
23 django/contrib/gis/oldforms/
@@ -1,14 +1,29 @@
+from django.core.validators import ValidationError
from django.oldforms import LargeTextField
+from django.contrib.gis.geos import GEOSException, GEOSGeometry
class WKTField(LargeTextField):
"An oldforms LargeTextField for editing WKT text in the admin."
+ def __init__(self, *args, **kwargs):
+ super(WKTField, self).__init__(*args, **kwargs)
+ # Overridding the validator list.
+ self.validator_list = [self.isValidGeom]
def render(self, data):
# Returns the WKT value for the geometry field. When no such data
# is present, return None to LargeTextField's render.
- if not data:
- return super(WKTField, self).render(None)
- else:
+ if isinstance(data, GEOSGeometry):
return super(WKTField, self).render(data.wkt)
+ elif isinstance(data, basestring):
+ return super(WKTField, self).render(data)
+ else:
+ return super(WKTField, self).render(None)
+ def isValidGeom(self, field_data, all_data):
+ try:
+ g = GEOSGeometry(field_data)
+ except GEOSException:
+ raise ValidationError('Valid WKT or HEXEWKB is required for Geometry Fields.')

0 comments on commit 8da13e6

Please sign in to comment.
Something went wrong with that request. Please try again.