[ZPT] URL quoting in ZPT

Jim Fulton jim@zope.com
Fri, 30 Aug 2002 07:57:31 -0400


Shane Hathaway wrote:
> 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.

I like this idea.  These tools must then be documented as part of
the ZPT docs.

Jim


-- 
Jim Fulton           mailto:jim@zope.com       Python Powered!
CTO                  (888) 344-4332            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org