Thanks for your reply, but the problem is there is no request.POST("var"), there is request.POST("var[foo]") and at that point I don't know all the possible values of "foo". I solved with with a custom extraction function.


While I'm at it, though, I wonder how others are solving the same problem. In PHP there are no sequences and dicts, just one associative array entity, so things like:

var['a']['b'] = c

are perfectly valid ad hoc, even if var was never used before, while Python would complain about missing key 'a' in dict var.

So the actual problem is this. I have a form with a table. Columns are entity fields, rows are individual entities, just like in a database. For a PHP backend the form would be constructed as:

<input type="text" name="foo[1]" value="123" />
<input type="text" name="bar[1]" value="123" />
<input type="text" name="baz[1]" value="123" />
<input type="text" name="gah[1]" value="123" />

with that being single row, entities having columns foo, bar, baz and gah, and the value in brackets is the row ID. One solution would be:

<input type="text" name="foo" value="123" />
<input type="text" name="bar" value="123" />
<input type="text" name="baz" value="123" />
<input type="text" name="gah" value="123" />
<input type="hidden" name="id" value="1" />

But I can't trust that the order given in the form is the same given through POST and especially the same reconstructed via WebOb's multidict entities (since Python's dicts are not ordered).

Another solution would be to serialize the form using, say, jQuery and do a JSON content type POST, then simply do json.loads(request.body) on the server side, but as I said, I don't want to modify the client if I don't have to. The best I can do is regex replace foo[id] into foo-id for easier parsing (field.split("-")).


Suggestions (I mean, other than using a lib or function that parses foo[id], bar[id], ...)?


.oO V Oo.


On 06/25/2011 03:28 PM, Stonly Baptiste wrote:
import simplejson>>>  mypost = request.params.POST('var')
json.loads('[%s]' % mypost[:-1])
Or something like that

You wouldn't have to change your php to send json, python could convert it to 
json

Thank you,
Stonly Baptiste
Aston UC is now Veddio Cloud Solutions
954.510.9642-Phone ext.104
877.357.7727-Toll Free ext.104
877.403.7036-Fax
[email protected] Email
http://www.veddio.com- Web
‪


--
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss?hl=en.

Reply via email to