[ZPT] URL quoting in ZPT

Shane Hathaway shane@zope.com
Thu, 29 Aug 2002 17:39:42 -0400 (EDT)


On Thu, 29 Aug 2002, Jeffrey P Shell wrote:

> On 8/29/02 3:12 PM, "Shane Hathaway" <shane@zope.com> wrote:
> > So there must be some simple way to get a string url_quoted, but I can't
> > think of what it would be.  Any suggestions?
>
> I always use ZTUtils.make_query these days.  It HTML quotes, it does Zope
> marshalling (:int, etc), and is easier to expand.  Usually I define a short
> variable to ZTUtils in an outer block or globally (tal:define="ztu
> modules/ZTUtils"), and then:
>
> <a tal:define="query python:ztu.make_query(id=myid)"
>    tal:attributes="href string:${here/absolute_url}?$query">Go</a>
>
> It's a bit more typing, but it's more flexible, especially when a query
> needs to be expanded.
>
> In the Products.PythonScripts.standard module are the 'url_quote' and
> 'url_quote_plus' formatting functions that DTML uses.

That's a good suggestion, though it is a lot of typing.  I was hoping for
something along the lines of:

<a tal:attributes="href
string:${here/absolute_url}?id=${url_quote: myid}">Go</a>

;-)

Maybe if we made ZTUtils available through a built-in name, we could
get most of the way there.  We could bind it to the name "utils" or,
perhaps better, "tools".  That way we could at least use
"python: tools.make_query(id=myid)" or
"python: tools.url_quote(myid)" without any hassle.

Shane