The idea...
If one constructs their HTML forms, naming their form elements as
"name[key]" like so:
<input type="text" name="f[name]">
<input type="text" name="f[address]">
<input type="text" name="f[city]">
etc.
Django would then convert this to a dictionary of form:
f = {
'name': 'value of f[name]',
'address': 'value of f[address]',
'city': 'value of f[city]'
}
This is also useful for grouping multiple select boxes:
<select multiple name="selects[]">
<option value="1">One</option>
<option value="2">Two</option>
<option value="2">Three</option>
</select>
(I'm not sure how Django handles multiple selects currently.)
Processing within Django, to me, becomes simpler, and one can do
things like the following rather than iterating over all items in
request.POST:
if request.POST.has_key('f'):
for k,v in request.POST['f'].iteritems():
# process key/value pairs in some way
Grouping your forms into dicts like this also lets you do iterative
logic while avoiding other POST items (eg: input type=submit values or
X,Y coordinates).
I'm not sure how this would tie in with newforms since we're not using
Django's forms and validation (at least for now).
Cheers!
Rob
I just opened a ticket regarding it's undocumented nature.
Interesting. I'm guessing it's not wired up to request.POST... I tried
naming my form like name="name.key" and got no DotExpandedDict love. :)
Thanks,
Rob
You'd just do the following line:
post = DotExpandedDict(request.POST)
then you'll have some love.