[<<] Industrie Toulouse
Part of the overall Zope Page Templates system is a package called ZTUtils. ZTUtils contains a number of useful functions and objects for Page Template and Python Script usage. Among other things, it contains a range of items for generating and dealing with trees (in replacement of the dtml-tree tag), batching, and assorted smaller helpers.

My favorite helper that I use in both Templates and Scripts is make_query. It does what its name says - it builds a query string. But it's more than that - it also properly marshals ZPublisher types, does url quoting, and more. So, gone are the days of building URL's like this:


  RESPONSE.redirect('page.pt?message=All+very+well+then')

And in are the days of:


  from ZTUtils import make_query
  query = make_query(message='All very well then')
  RESPONSE.redirect('page.pt?%s' % query)

While it doesn't look terribly impressive, it's when query parameters start to build up that it's the most useful. And the intent is clearer. A page template example, based on working code:


  <ul tal:define="ztu modules/ZTUtils; MQ python:ztu.make_query">
    <li>
     <a tal:attributes="href python:'./force.py?%s' % MQ(item_id=item.id,status=4)"
     >set all to passed</a>
  </ul>

When the url is generated, it comes out as:


  ./force.py?item_id=IXL0102&status:int=4