[Zope] Re: how to accumulate data using ZPT

Chris McDonough chrism at plope.com
Fri May 20 07:06:10 EDT 2005


Use two things: a page template and a Python script... here's an
example:

page template body
------------------

<div tal:define="L python: [1,2,3,4];
                 A python: context.sum_of(L)">
   <div tal:repeat="V L"
         tal:content="V">1</div>
   <div tal:content="A">total</div>
</div>

python script "sum_of" body
---------------------------
## Script (Python) "sum_of"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=L
##title=
##
x = 0
for val in L:
   x = x + val
return x


On Fri, 2005-05-20 at 03:54 -0700, prabuddha ray wrote:
> sorry for delay, 
>          but the options you gave are ruled out.
> actually not all the rows in the column have the values.
> further the total i'm looking for will result in a very complex query 
> that i dont want to do onsidering the no. of rows are high.
>           
>   I just need something like a var in my ZPT which can just sum up the
> values if they  are present.
> value's prsence i'm checking using tal:condition but how to add the
> value repeatedly in the sum var.
> 
> kindly help.
> 
> 
> 
> On 5/20/05, Tino Wildenhain <tino at wildenhain.de> wrote:
> > Am Freitag, den 20.05.2005, 10:36 +0100 schrieb Hugo Ramos:
> > > On 5/20/05, Tino Wildenhain <tino at wildenhain.de> wrote:
> > > > Am Freitag, den 20.05.2005, 09:52 +0100 schrieb Hugo Ramos:
> > > > > Yellow,
> > > > >
> > > > > What DBMS are you using??? MySQL???
> > > > > If so just have a sql method do this:
> > > > > ==========
> > > > > SELECT COUNT( '*' )  AS total
> > > > > FROM yourtable
> > > > > ==========
> > > > 
> > > > Are you sure about the ' '? looks strange.
> > > 
> > > It works both ways... With or without the ' ' !
> > > 
> > well. another reason to avoid mysql I guess ;)
> > 
> > 
> > 
> > 
> 
> 



More information about the Zope mailing list