[ZPT] Using ZSQL from ZPT

Harry Wilkinson harryw@nipltd.com
Thu, 21 Mar 2002 17:01:49 +0000


I find it easier to call the .dictionaries() method of the returned results 
set and use a list of dictionaries rather than a results object:

  <tr tal:repeat="results
python:container.DataReader.getResults(usr_name=container.portal_membership
 getAuthenticatedMember().getUserName()).dictionaries()">>
    <td tal:content="results/fieldname1">content for field1</td>
    <td tal:content="results/fieldname2">content for field2</td>
  </tr>


On Thursday 21 March 2002 4:38 pm, Brian Watson wrote:
> Hello Everyone,
>
> I'm trying to iterate over the results of a ZSQL Method in ZPT.  I just
> need a table row displaying each column in the db table for each table row
> returned from the method.  I'm trying it like this:
>
>   <tr tal:repeat="results
> python:container.DataReader.getResults(usr_name=container.portal_membership
>. getAuthenticatedMember().getUserName())">>
>     <td tal:content="python:results[][]">content</td>
>     <td tal:content="python:results[][]">content</td>
>   </tr>
>
> and I've also tried the results/... way, but still no luck (the item/x way
> just doesn't work and the [] way results in an unscriptable object error).
> How do I use the results or is there a preferred way to do this?  I've seen
> two solutions: call a script that fixes up the ZSQL results before
> returning them to ZPT and call a script first that fixes the results and
> then calls the ZPT passing the results in a built-in ZPT variable.  It just
> seems like ZSQL is so ingrained in Zope that there should be a simple way
> to use them in ZPT.
>
> Thanks in advance,
> Brian W.
>