From dd793cf55497c06101143942e0439dd409381df3 Mon Sep 17 00:00:00 2001
From: Daniel Barreto <daniel@gia.usb.ve>
Date: Thu, 10 Feb 2011 18:32:46 -0430
Subject: [PATCH 83/83] Added to_python to GeometryField, which transform the given value to a Geometry object and it's called before cleaning that value.
---
django/contrib/gis/forms/fields.py | 16 +++++++++++-----
1 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/django/contrib/gis/forms/fields.py b/django/contrib/gis/forms/fields.py
index f806dcb..0b71774 100644
a
|
b
|
class GeometryField(forms.Field):
|
29 | 29 | self.null = kwargs.pop('null', True) |
30 | 30 | super(GeometryField, self).__init__(**kwargs) |
31 | 31 | |
| 32 | def to_python(self, value): |
| 33 | """Transforms the value to a Geometry object.""" |
| 34 | # Trying to create a Geometry object from the form value. |
| 35 | try: |
| 36 | geom = GEOSGeometry(value) |
| 37 | except: |
| 38 | raise forms.ValidationError(self.error_messages['invalid_geom']) |
| 39 | return geom |
| 40 | |
32 | 41 | def clean(self, value): |
33 | 42 | """ |
34 | 43 | Validates that the input value can be converted to a Geometry |
… |
… |
class GeometryField(forms.Field):
|
42 | 51 | else: |
43 | 52 | raise forms.ValidationError(self.error_messages['no_geom']) |
44 | 53 | |
45 | | # Trying to create a Geometry object from the form value. |
46 | | try: |
47 | | geom = GEOSGeometry(value) |
48 | | except: |
49 | | raise forms.ValidationError(self.error_messages['invalid_geom']) |
| 54 | # Transform the value to a python object first |
| 55 | geom = self.to_python(value) |
50 | 56 | |
51 | 57 | # Ensuring that the geometry is of the correct type (indicated |
52 | 58 | # using the OGC string label). |