On Jun 18, 2007, at 3:40 PM, m h wrote:
If I have a python object like above I can pass in this python object to my template and create an analogous javascript version pretty easily. My question has to do with sending this data back in a form.One way to do it is create a form parameter for each key and value. Instead of using the key as the actual key, I could use some predetermined naming scheme, so the parameters would be sent like this (assuming the actual values are the names of the variables above for simplicity sake, and assuming that "..." means no value): K1=key1 V1=value1 V1=value2 K2=key2 V2=value3 K3=key3 V3=value4 Then when processing I can just iterate over all http parameters and if the start with "K" followed by an int I assume they are part of this dictionary, and then recreate my mapping on the server side. Another way would be to try and create a long string and put some psuedo-unique delimiters in the string ie: MYDICT=key1||value1||value2,,key2||value3,,key3||value4 Neither of these solutions feels good to me. But I think out of the two I prefer the former (just to avoid the delimiter actually occurring in the string, (probably wouldn't in practice)). If anyone cares to share experiences/comments passing around similar structures, I'm all ears.
Generally, if I need to move information around like that in a form, and have it put into a structure, I use FormEncode. The variabledecode module actually sets up a way to have form items collected into either a list or dict, or both depending on the structure of the form names.
http://formencode.org/module-formencode.variabledecode.htmlThat would take care of pulling the data from the form back into an object, I'd imagine it'd be easy enough to create a little function that spits out some hidden fields (Assuming you want them hidden) that creates them with the appropriate names for some objects.
Cheers, Ben
smime.p7s
Description: S/MIME cryptographic signature
