[ZPT] ZSQL Batchine

Joel Burton joel@joelburton.com
Thu, 1 Aug 2002 14:39:35 -0400 (EDT)


On Thu, 1 Aug 2002, Jim Kutter wrote:

> Hi folks
>
> I've looked high and low, and I can't find any examples how to run a
> SQL query, batching the results from ZPT
>
> i have a query that returns like 50 items, I need them displayed in
> two columns on a page, first 25 in one column, second 25 in the next
> column. I've seen that in DTML using the start and size arguments to
> the ZSQL method, but it befuddles me as to how to tell the ZSQL method
> that stuff in ZPT.
>
> Does anyone know?
>
> -jim

Simple setup:

<div tal:define="list here/sqlSelectMethod;">
  <table>
    <tr>
      <td>
        <p tal:repeat="item python: list[:25]" tal:content="item/colA" />
      </td>
      <td>
        <p tal:repeat="item python: list[25:]" tal:content="item/colB" />
      </td>
    </tr>
  </table>
</div>

This isn't batching per se -- normally, batching refers to displaying
results over several pages. However, you could use this strategy with
batching--just cut the returned batch in half, as above.

This solution hard codes 25 as half the list size--you could instead cut
the list by using len(list)/2.

I have a small q&d script that cuts any list into n number of balanced
sublists. Then, you can say define="sublists python:listSplit(list,3)"
to cut your list into 3 equal chunks, as sublist[0], sublist[1],
sublist[2].

HTH.

 --

Joel BURTON  |  joel@joelburton.com  |  joelburton.com  |  aim: wjoelburton
Independent Knowledge Management Consultant