FWIW, In Ian Bicking's FormEncode package there is a form variable
decoder which does something similar to what you want and maybe of
interest to you. To quote from the source code:

"""
Takes GET/POST variable dictionary, as might be returned by ``cgi``,
and turns them into lists and dictionaries.

Keys (variable names) can have subkeys, with a ``.`` and
can be numbered with ``-``, like ``a.b-3=something`` means that
the value ``a`` is a dictionary with a key ``b``, and ``b``
is a list, the third(-ish) element with the value ``something``.
Numbers are used to sort, missing numbers are ignored.
"""

Using these conventions, you query string would have been:

  myurl/?
countries.visited-1=us&countries.visited-2=dk&countries.notvisited-1=be

For the source, see:

  http://svn.colorstudy.com/FormEncode/trunk/formencode/variabledecode.py

Graham


On May 4, 1:43 am, simonbun <[EMAIL PROTECTED]> wrote:
> Suppose the following query parameters:
> myurl/?var=1&var=2&var=3
>
> Running this through QueryDict correctly gives me
> <MultiValueDict: {'var': ['1', '2', '3']}>
>
> I had hoped that multiple levels in these variables would result in a
> nested dictionary, but no such luck. To illustrate the problem lets
> suppose the following query:
>
> myurl/?
> countries[visited]=us&countries[visited]=dk&countries[notvisited]=be
>
> It gets parsed as
> <MultiValueDict: {'countries[visited]': ['us', 'dk'],
> 'countries[notvisited]': ['be']}>
>
> yet i would have hoped:
> <MultiValueDict: {'countries': {'visited': ['us', 'dk'], 'notvisited':
> ['be']}}>
>
> I'm thinking it would be better to have QueryDict recurse through the
> values instead of just parsing one level deep. Is there a way to
> achieve what I want, or is this handled at themod_pythonlevel?
>
> Regards,
> Simon


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" 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/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to