Hello again!

Some details about problem:

Here is method on my Manipulator class based on forms.Manipulator:

    def getForm(self, data, errors):
        form = forms.FormWrapper(self, data, errors)
        # There some debug output
        debug("Data is: " +repr(data))
        for field in form.fields:
            debug(field)
        return field

After changing client from Malishev to Orion via external form
(clicked on "change client" link) function debug displayed:

edit_zone: [('21', 'Malishev: 500 (500)')]
edit_zone: [('21', 'Malishev: 500 (500)')]
edit_zone: [('20', 'Orion: 1000 (1000)')]
Data is: {'instance': 20, 'access_allowed': True, 'zone': 2}
<select id="id_instance" class="vSelectField" name="instance" size="1">
    <option value="21">Malishev: 500 (500)</option>
  </select>
<select id="id_instance" class="vSelectField" name="instance" size="1">
    <option value="21">Malishev: 500 (500)</option>
  </select>
<select id="id_instance" class="vSelectField" name="instance" size="1">
    <option value="20">Orion: 1000 (1000)</option>
  </select>

So form.fields contains 3 (!!!!) fields with the same name "instance",
but data which passed into forms.FormWrapper contains only 1.

Ok, do some magic and changing method getForm  and add some debug
output into view function

   def getForm(self, data, errors):
        form = forms.FormWrapper(self, data, errors)
        debug("Data is: " +repr(data))

        data_repr = []

        fields = {}

        for field in self.fields:
            fields[field.field_name] = field

        form._fields = fields.values()
        for field in form.fields:
            if field.field_name != 'instance': continue
            debug(field)
        return form

and important part from views.py:
    # Get the form from manipulator. It is FormWrapper object
    base_context['form'] = manipulator.form
    # Print interessed for us field "instance"
    for field in base_context['form'].fields:
        if field.field_name != 'instance': continue
        debug("Edit_zone: " +str(field))

    # Also get the same field by __getitem__ method
    debug("form.instance: " +str(base_context['form'].__getitem__('instance')))

Changing client back from Orion to Malishev and Malishev to Orion.
Debug contains:
   edit_zone: [('21', 'Malishev: 500 (500)')]
   edit_zone: [('20', 'Orion: 1000 (1000)')]
   Data is: {'instance': 20, 'access_allowed': True, 'zone': 2}
   <select id="id_instance" class="vSelectField" name="instance" size="1">
       <option value="20">Orion: 1000 (1000)</option>
   </select>
   Edit_zone: <select id="id_instance" class="vSelectField"
name="instance" size="1
">
       <option value="20">Orion: 1000 (1000)</option>
    </select>
    form.instance: <select id="id_instance" class="vSelectField"
name="instance" size="1">
        <option value="21">Malishev: 500 (500)</option>
    </select>

What we see? base_context['form'].fields contains proper data, but
__getitem__ returned incorrect!

Test case with 100% repetition can be obtained from
http://hosting.svr.net.ua/~ad/test.tgz

Tested on Windows, FreeBSD, Linux with python 2.4.2 and 2.4.3 with
mod_python 3.2.10 and django-admin.py runserver

-- 
Andrew Degtiariov
DA-RIPE

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to