Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » AddManipulator does not populate select [RSS Feed]

#1 Dec. 3, 2005 06:15:32

Kenneth G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

AddManipulator does not populate select


hi,
when using AddManipulator and returning the form for correcting
errors, the select field does not get populated with the choice
selected. I could do this manually, but does django have a way of
doing it automatically?
--
regards
kghttp://www.livejournal.com/users/lawgontally ho!http://avsap.org.inಇಂಡ್ಲಿನಕ್ಸ வாழ்க!

Offline

#2 Dec. 3, 2005 11:19:32

Robert W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

AddManipulator does not populate select


Kenneth Gonsalves wrote:
> hi,
> when using AddManipulator and returning the form for correcting
> errors, the select field does not get populated with the choice
> selected. I could do this manually, but does django have a way of
> doing it automatically?

If using trunk, are you using flatten_data as directed inhttp://code.djangoproject.com/wiki/NewAdminChanges?

These changes need to go into the tutorial and other documentation.

Offline

#3 Dec. 3, 2005 12:05:26

Kenneth G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

AddManipulator does not populate select


On Saturday 03 Dec 2005 4:48 pm, Robert Wittams wrote:
> Kenneth Gonsalves wrote:
> > hi,
> > when using AddManipulator and returning the form for correcting
> > errors, the select field does not get populated with the choice
> > selected. I could do this manually, but does django have a way
> > of doing it automatically?
>
> If using trunk, are you using flatten_data as directed in
>
>http://code.djangoproject.com/wiki/NewAdminChanges?

this only describes how to do it in ChangeManipulator - i used
flatten_data in the AddManipulator like this:

if request.POST:
        data = request.POST.copy()
        errors = manipulator.get_validation_errors(data)
        manipulator.do_html2python(data)
        data = manipulator.flatten_data()
        if not errors:
           
            enquiry = manipulator.save(data)
            return HttpResponseRedirect("/yyy/xxx/")

but the select field still didnt get populated

--
regards
kghttp://www.livejournal.com/users/lawgontally ho!http://avsap.org.inಇಂಡ್ಲಿನಕ್ಸ வாழ்க!

Offline

#4 Dec. 3, 2005 12:23:58

Robert W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

AddManipulator does not populate select


Kenneth Gonsalves wrote:
> On Saturday 03 Dec 2005 4:48 pm, Robert Wittams wrote:
>
>>Kenneth Gonsalves wrote:
>>
>>>hi,
>>>when using AddManipulator and returning the form for correcting
>>>errors, the select field does not get populated with the choice
>>>selected. I could do this manually, but does django have a way
>>>of doing it automatically?
>>
>>If using trunk, are you using flatten_data as directed in
>>
>>http://code.djangoproject.com/wiki/NewAdminChanges?
>
>
> this only describes how to do it in ChangeManipulator - i used
> flatten_data in the AddManipulator like this:
>
> if request.POST:
> data = request.POST.copy()
> errors = manipulator.get_validation_errors(data)
> manipulator.do_html2python(data)
> data = manipulator.flatten_data()
Erm...throwing away the data we got from the POST...
> if not errors:
>
> enquiry = manipulator.save(data)
> return HttpResponseRedirect("/yyy/xxx/")
>
> but the select field still didnt get populated
>
Why are you flattening the data again? You only do this once, when
extracting the data out of the object instance (or the defaults). The
data is already 'flat' when it comes out of a POST. do_html2python gets
it back into a form suitable for both saving and populating form fields.

What you are doing here is getting the default data out of the
manipulator again as far as I can tell.

Offline

#5 Dec. 3, 2005 12:40:52

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

AddManipulator does not populate select


Robert Wittams wrote:Why are you flattening the data again? You only do this once, when
extracting the data out of the object instance (or the defaults). The
data is already 'flat' when it comes out of a POST. do_html2python gets
it back into a form suitable for both saving and populating form fields.Uhm... So "flatten_data" is essentially "do_python2html"? If yes, may bejust rename it to prevent confusion?

Offline

#6 Dec. 3, 2005 12:51:26

Kenneth G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

AddManipulator does not populate select


On Saturday 03 Dec 2005 5:50 pm, Robert Wittams wrote:
> Kenneth Gonsalves wrote:
> > On Saturday 03 Dec 2005 4:48 pm, Robert Wittams wrote:
> >>Kenneth Gonsalves wrote:
> >>>hi,
> >>>when using AddManipulator and returning the form for
> >>> correcting errors, the select field does not get populated
> >>> with the choice selected. I could do this manually, but does
> >>> django have a way of doing it automatically?
> >>
> >>If using trunk, are you using flatten_data as directed in
> >>
> >>http://code.djangoproject.com/wiki/NewAdminChanges?
> >
> > this only describes how to do it in ChangeManipulator - i used
> > flatten_data in the AddManipulator like this:
> >
> > if request.POST:
> > data = request.POST.copy()
> > errors = manipulator.get_validation_errors(data)
> > manipulator.do_html2python(data)
> > data = manipulator.flatten_data()
>
> Erm...throwing away the data we got from the POST...
>
> > if not errors:
> >
> > enquiry = manipulator.save(data)
> > return HttpResponseRedirect("/yyy/xxx/")
> >
> > but the select field still didnt get populated
>
> Why are you flattening the data again? You only do this once,
> when extracting the data out of the object instance (or the
> defaults). The data is already 'flat' when it comes out of a
> POST. do_html2python gets it back into a form suitable for both
> saving and populating form fields.
>
> What you are doing here is getting the default data out of the
> manipulator again as far as I can tell.

ok - it works now thanks

--
regards
kghttp://www.livejournal.com/users/lawgontally ho!http://avsap.org.inಇಂಡ್ಲಿನಕ್ಸ வாழ்க!

Offline

#7 Dec. 3, 2005 18:05:36

Robert W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

AddManipulator does not populate select


Maniac wrote:
>
> Robert Wittams wrote:
>
>> Why are you flattening the data again? You only do this once, when
>> extracting the data out of the object instance (or the defaults). The
>> data is already 'flat' when it comes out of a POST. do_html2python gets
>> it back into a form suitable for both saving and populating form fields.
>>
>>
> Uhm... So "flatten_data" is essentially "do_python2html"? If yes, may be
> just rename it to prevent confusion?
>
No. Read the source before suggesting changes to it.

Offline

#8 Dec. 3, 2005 18:18:50

Robert W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

AddManipulator does not populate select


Robert Wittams wrote:
> Maniac wrote:
>
>>Robert Wittams wrote:
>>
>>
>>>Why are you flattening the data again? You only do this once, when
>>>extracting the data out of the object instance (or the defaults). The
>>>data is already 'flat' when it comes out of a POST. do_html2python gets
>>>it back into a form suitable for both saving and populating form fields.
>>>
>>>
>>
>>Uhm... So "flatten_data" is essentially "do_python2html"? If yes, may be
>>just rename it to prevent confusion?
>>
>
> No. Read the source before suggesting changes to it.
>

What I mean here is that do_html2python and flatten_data are not
inverses of one another, and so its a bad idea to name them as if they are.

tbh, do_python2html is a horrible name anyway.
At some point we are going to need to renovate the whole lot of

.do_python2html
.get_validation_errors
and the bit of .save that makes objects,

in order to allow for validations based on objects rather than unprocess
ed POST data, and rational dealing with files.

Something like
object, data, errors = manipulator.process_request(request)

....

Not sure of how exactly this would end up though.

Robert

Offline

  • Root
  • » Django
  • » AddManipulator does not populate select [RSS Feed]

Board footer

Moderator control

Enjoy the 22nd of April
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support