Discussion:
[Erp5-dev] count method in listbox
Yoshinori Okuji
2005-04-11 15:50:11 UTC
Permalink
I have added yet another attribute into ListBox. A "Count Method" is used to
count the number of objects correctly. This feature is optional, so you do
not have to it. Using this feature, however, is recommended for the
performance improvement. It changes significantly if a module has many
objects.

Here I describe how to use it:

- Add support for limit_expression into a list method. Add limit_expression
into "Arguments", and add this into the SQL:

<dtml-if limit_expression>
LIMIT <dtml-var "limit_expression">
<dtml-else>
LIMIT 1000
</dtml-if>

You can change the default limit to whatever else you like.

- Set "Maximum rows to retrieve" to zero, so that ZMySQLDA won't add LIMIT
automatically.

- Make a count method. For consistency, I recommend using the same Z SQL Mehod
as the list method. You can use dtml conditionals to return different
information, like this:

SELECT
<dtml-if stat>
SUM(stock.quantity) AS quantity
<dtml-elif count>
COUNT(DISTINCT catalog.id) AS count
<dtml-else>
DISTINCT
<dtml-in "portal_catalog.getCatalogSearchResultKeys()"> <dtml-var
sequence-item> <dtml-unless sequence-end>,</dtml-unless> </dtml-in>
<dtml-if select_expression>, <dtml-var select_expression> </dtml-if>
</dtml-if>
...

- If a ListBox uses portal_catalog for a list method, you can just specify
portal_catalog for the count method as well. This results in calling
portal_catalog.countResults after all.

YO
--
Yoshinori Okuji, Nexedi Research Director
Nexedi: Consulting and Development of Free / Open Source Software
http://www.nexedi.com
ERP5: Free / Open Source ERP Software for small and medium companies
http://www.erp5.org
Storever: OpenBrick, WiFi infrastructure, notebooks and servers
http://www.storever.com
Loading...