[Zope] build a query string out of a dictionary (REQUEST.form)

Andy McKay andym@ActiveState.com
Wed, 11 Jul 2001 08:10:02 -0700


> I'd like to access it in a DTML method or Python Script.
> I just tried to program a small Python Script, but methods
> out of urlib can not be used :-(

Use an External Method then.

>   <dtml-let qs=3D"buildQueryString(REQUEST.form, replace=3D{'foo':'bar'=
})">
>   <a href=3D"dtml-absolute_url;>?<dtml-qs>">foobar</a>
>   </dtml-let>

A simple python method that loops through the form doesnt need urllib.

eg:

for k, v in context.REQUEST.form.items():
    if k =3D=3D 'foo':
        # do something
    else:
        somestr =3D '%s&%s=3D%s' % (somestr, k, v)

Cheers.
--
  Andy McKay.


> The purpose is to append the actual query string to a link.
> But I like to replace parts of the query!
> I'd like to build a link the following way (DTML snippet):
>
>   <dtml-let qs=3D"buildQueryString(REQUEST.form, replace=3D{'foo':'bar'=
})">
>   <a href=3D"dtml-absolute_url;>?<dtml-qs>">foobar</a>
>   </dtml-let>
>
> So a form value of e.g. 'foo=3Dxxx' would be replaced by 'foo=3Dbar'.
>
> I saw discussions about this topic in the list, but no
> answers with usable solutions. Did I miss it?
>
> I don't like to make a Product to support this! Ok, if I
> need I'll would have to :-(
>
> Greg
> _____________________________________
> Gr=E9goire Weber
> mailto:gregoire.weber@switzerland.org
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>