#15271: django.contrib.gis.forms.fields.GeometryField should call to_python 
before
cleaning
-------------------------------------+-------------------------------------
     Reporter:  volrath              |                    Owner:  copelco
         Type:  Bug                  |                   Status:  assigned
    Component:  GIS                  |                  Version:  SVN
     Severity:  Normal               |               Resolution:
     Keywords:  gis, field, clean,   |             Triage Stage:  Accepted
  to_python                          |      Needs documentation:  0
    Has patch:  1                    |  Patch needs improvement:  0
  Needs tests:  1                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by copelco):

 To illustrate volrath's suggested changes, the provided patch would allow
 you to do something along the lines of this:

 {{{#!python
 from django import forms
 from django.contrib.gis.forms import GeometryField


 class CoordsWidget(forms.MultiWidget):

     def __init__(self, *args, **kwargs):
         widgets = (forms.TextInput(), forms.TextInput())
         super(CoordsWidget, self).__init__(widgets, *args, **kwargs)

     def decompress(self, value):
         return value.coords


 class CoordsField(GeometryField):
     widget = CoordsWidget

     def to_python(self, value):
         wkt = "POINT({0} {1})".format(value[0], value[1])
         return super(CoordsField, self).to_python(wkt)


 class LocationForm(forms.ModelForm):

     point = CoordsField()

     class Meta(object):
         model = Location
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/15271#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to