[Zope] Re: Output only the first or a particular record using TAL

Julian Yap julian_yap at yahoo.com
Wed Sep 28 02:32:08 EDT 2005


--- Chris Withers <chris at simplistix.co.uk> wrote:
> > I used the following and it works great (without some
> formatting for
> > clarity):
> > <tr tal:define="customer container/getCustomerLicences"
> > tal:condition="customer">
> >     <td>Customer: <span
> > tal:content="python:customer[0]['full_name']"></span></td>
> > </tr>
> 
> hmm, this strikes me as just plain wrong :-S
> 
> Why is getCustomerLicenses returning more than one row if you
> only want 
> the first one?

In my original post I mentioned that getCustomerLicenses returns
more than one row and I want to create something of a header.

> If it only returned one row, then you could do:
> 
> <tr tal:repeat="customer container/getCustomerLicences">
>   <td>
>    Customer:
>    <span tal:content="customer/full_name"></span>
>   </td>
> </tr>
> 
> ...no need for the condition or the yucky integer indexes.

True.

> Now, if you really can't stop your sql returning more than one
> row 
> (LIMIT 1 anyone?) then how about:
> 
> <tr tal:define="customers container/getCustomerLicences;
>                  customer  python:customers and customers[0]"
>      tal:condition="customer">
>   <td>
>    Customer:
>    <span tal:content="customer/full_name"></span>
>   </td>
> </tr>

To have my SQL returning only just 1 row would require another Z
SQL Method, in which case it may as well be something like
getCustomer.

I'm still getting my head around TAL and how it works so I'm not
sure how the "python:customers and customers[0]" code works.

Ideally, I want to use just the one Z SQL method (done) but I
guess it would be better coding to just reference the Z SQL
method once.  Currently the page template makes two calls to the
Z SQL method.  Once for the customer header and another to
retrieve the customer license details.  Can you suggest how this
would be done?

I'm also thinking further along the lines too of a page
template, printing all customers with headers and details for
each.  This would use a SQL "GROUP BY" statement.  .. But this
is still out of my scope of knowledge.

Regards,
Julian



More information about the Zope mailing list