Ticket #15271: 0001-Added-to_python-to-GeometryField-which-transform-the.patch

File 0001-Added-to_python-to-GeometryField-which-transform-the.patch, 1.8 KB (added by Daniel Barreto, 14 years ago)
  • django/contrib/gis/forms/fields.py

    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):  
    2929        self.null = kwargs.pop('null', True)
    3030        super(GeometryField, self).__init__(**kwargs)
    3131
     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
    3241    def clean(self, value):
    3342        """
    3443        Validates that the input value can be converted to a Geometry
    class GeometryField(forms.Field):  
    4251            else:
    4352                raise forms.ValidationError(self.error_messages['no_geom'])
    4453
    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)
    5056
    5157        # Ensuring that the geometry is of the correct type (indicated
    5258        # using the OGC string label).
Back to Top