[<<] Industrie Toulouse
"Zope" has many delightful aspects that arise out of its very basic nature as a Web Object Publisher - that is, an ORB (Object Request Broker) that turns HTTP, FTP, WebDAV, and potentially other requests into Python object calls.

There's a really cool trick that arises out of Zope's SQL Methods and Acquisition, where you can go directly to a single result out of a relational database. It's generally known as direct traversal. What it does is basically turn URL Path pieces into parameters passed into a SQL Method. SQL Methods are part of Zope's relational database story - a separate DTML based SQL template (the SQL Method), posing as a callable Python/Zope object. SQL Methods make use of some extended DTML tags to ease dynamic SQL authoring. A simple, but rather powerful SQL Method might look like:


id: getPackage
params: package_id=""
 
SELECT package_id, name, price FROM PACKAGES
<!--#sqlgroup where-->
 <!--#sqltest package_id type=int multiple optional-->
<!--#/sqlgroup-->

When a 'package_id' parameter is passed, the entire 'sqlgroup where' block will render out into a full SQL 'Where' clause - if more than one value is passed in for 'package_id', the sqltest statement will even generate 'package_id IN ...' code. If no value(s) are passed in, the whole 'where' clause will be dropped (in this case - there's a lot of power in the dtml-sqlXXX tags).

The cool tricks come with direct traversal, where you can treat a SQL Result object like a local one. What this means is that a URL like:

../site/getPackage/package_id/2/menu.html

actually causes the getPackage SQL Method to be called, with the value '2' passed in to the package_id parameter. Traversal continues at this point, allowing menu.html to be acquired and rendered in the context of the result of 'getPackage'. Thus, if 'menu.html' were a Page Template, it could contain code like:


<h2 tal:content="here/name">Package Name</h2>
 
<p tal:content="here/price">package price...</p>
 
<a href="packages.html" 
    tal:attributes="href string:${container/absolute_url}/packages.html"
 >Return to package listing</a>

Notice the use of here, a page template context meaning the local context of where the template is being executed. The final line uses the 'container' context, which is where the template physically resides in Zope, to render a URL to get back to the package listing (placing the value of the TALES expression in the 'href' attribute of the anchor tag).

Since this example SQL Method has only one parameter, it can actually be configured to do Simple Direct Traversal, whereby the URL could be shortened down to:

.../site/getMenu/2/menu.html

and "Zope" would match the first value after the SQL Method in the URL to its 'package_id' parameter. Or, you could have URL's with many parameters, such as:

.../site/getMenu/menu_id/2/restaurant_id/4/menu.html

Which would pass in '2' to the 'menu_id' parameter, and '4' to a notional 'restaurant_id' parameter.

There's even more power that can be reaped by using Brains, classes (Python or ZClasses) that can be mixed in with the result to add extra computing power (or other tricks one might figure out to make a simple O-R Mapping system). And ever more power beyond that.