[ZPT] SQL Methods and arguments

wade@okaynetwork.com wade@okaynetwork.com
Tue, 04 Jun 2002 17:52:34 -0400


>Subject: Re: [ZPT] SQL Methods and arguments
>From: Casey Duncan <casey@zope.com>
>To: Jim Kutter <jim@ebizq.net>
>Cc: zpt@zope.org
>Date: 03 Jun 2002 16:15:49 -0400
>
>On Mon, 2002-06-03 at 14:17, Jim Kutter wrote:
>> Hiya
>> 
>> I want to have a page template that displays the fields of a db record. The row id of the record is passed to the template in a GET variable. I only want that item to be displayed (not all the records in a table, 
that I can do)
>> 
>> I don't want to code the display of the item in DTML or python because I want my designers to be able to modify the page easily.
>> 
>> How would I do this?
>> 
>> -jim
>
>I think the answer lies in the "Simple Direct Traversal" support in ZSQL
>methods (turn it on in the advanced tab). This allows you to use a url
>like:
>
>http://myzope/sqlMethod/rowid/pageTemplate.html
>
>Where rowid is a primary key value in the table (sqlMethod must take
>only one argument). In pageTemplate.html you can then do things like:
>
>  Some Field: <span tal:replace="here/field_name">Sample Value</span>
>
>A google search for "Direct Traversal" brought up this example by Chris
>McDonough, which is in DTML, but is conceptually the same.
>
>  http://www.zope.org/Members/mcdonc/HowTos/direct_traversal
>
>hth,
>
>-Casey
>

Alternatively, if your query is too complicated for direct traversal, you could make the
Url point to a Python Script, which would call the ZSQL method, massage the
results as necessary, then call a Page Template, passing it the result set.

I find myself using this pattern almost all the time -- 
the Python Script is the hub. If necessary I can then call
different Page Templates in different circs. 

-- Wade Leftwich
Ithaca, NY