[Zope] Re: how to accumulate data using ZPT

2005-05-24 Thread prabuddha ray
 ok this is again freaky on my part.

my problem still remains intact .as i've told earlier,
in my ZPT I needed to find a way to sum up column values 
if they are present and print the total at the last row.

I tried this as a Deepak pal tipped :

span tal:condition=not:penaltylen tal:content=python:penalty[0].unit_cost/
span tal:define=global sum python:sum+penalty[0].unit_cost/
 trtdTotal tdb tal:content=sum/b/td/tr

 but what happens is obvious , for reports where even one row has the
unitcost missing followiing error comes up:

tuple indx out of range

when i changed tghe span tgs alike this :

span tal:condition=not:penaltylen tal:content=python:penalty[0].unit_cost
span tal:define=global sum python:sum+penalty[0].unit_cost/
/span

no error was there but the total remained 0.

No ZSQLmethod can be used to get the sum coz its pretty complex.

 so plz rethink the code I'm also trying hard.
 hope for a reply soon
 
 On 5/20/05, Deepak [EMAIL PROTECTED] wrote:
  
  Hi Prabuddha,
 
  check this ...
  
  span tal:define=global sum python:0/
  span tal:repeat=item python:here.somesql()
  span tal:condition=item/var tal:define=global sum 
  python:sum+item.var/
  /span
  span tal:content=sum/
  
  thanks,
  
  Deepak
  
  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 [EMAIL PROTECTED] wrote:

  
  Am Freitag, den 20.05.2005, 10:36 +0100 schrieb Hugo Ramos:
  
  
  On 5/20/05, Tino Wildenhain [EMAIL PROTECTED] 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 ;)
  
  
  
  
  
  
  
  

  
  
  
  
 


-- 
Share the vision of difference with ME
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Re: how to accumulate data using ZPT

2005-05-24 Thread Deepak





What r those "penaltylen" and "penalty"? and also can u tell us y u r
checking "not:penaltylen"?

regards,
Deepak

prabuddha ray wrote:

   ok this is again freaky on my part.

my problem still remains intact .as i've told earlier,
in my ZPT I needed to find a way to sum up column values 
if they are present and print the total at the last row.

I tried this as a Deepak pal tipped :

span tal:condition="not:penaltylen" tal:content="python:penalty[0].unit_cost"/
span tal:define="global sum python:sum+penalty[0].unit_cost"/
 trtdTotal tdb tal:content="sum"/b/td/tr

 but what happens is obvious , for reports where even one row has the
unitcost missing followiing error comes up:

"tuple indx out of range"

when i changed tghe span tgs alike this :

span tal:condition="not:penaltylen" tal:content="python:penalty[0].unit_cost"
span tal:define="global sum python:sum+penalty[0].unit_cost"/
/span

no error was there but the total remained 0.

No ZSQLmethod can be used to get the sum coz its pretty complex.

 so plz rethink the code I'm also trying hard.
 hope for a reply soon
 
  
  
On 5/20/05, Deepak [EMAIL PROTECTED] wrote:


  Hi Prabuddha,
   
check this ...

span tal:define="global sum python:0"/
span tal:repeat="item python:here.somesql()"
span tal:condition="item/var" tal:define="global sum 
python:sum+item.var"/
/span
span tal:content="sum"/

thanks,

Deepak

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 [EMAIL PROTECTED] wrote:
 



  Am Freitag, den 20.05.2005, 10:36 +0100 schrieb Hugo Ramos:
   

  
  
On 5/20/05, Tino Wildenhain [EMAIL PROTECTED] 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 ;)




   

  


 


  
  

  

  
  

  




___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Re: how to accumulate data using ZPT

2005-05-24 Thread prabuddha ray
sorry,
i missed the xplanaition.
i think this'll explain...
div tal:define= penalty   
python:context.getPenalty(group_code=gcode,item_code=icode);
 penaltylen python:test(len(penalty)==0)

so not:penaltylen ensures that unit_cost is present for this row.

anyway i think this worked finally :
 td
  span tal:condition=not:penaltylen
  span tal:define=unit_cost python:penalty[0].unit_cost;
global sum python:sum+unit_cost tal:content=unit_cost/
 /span

tdb tal:content=sum/b/td/tr

thanks deepak

On 5/24/05, Deepak [EMAIL PROTECTED] wrote:
 
 What r those penaltylen and penalty? and also can u tell us y u r 
 checking  not:penaltylen?
 
 regards,
 Deepak
 
 prabuddha ray wrote:
 
  ok this is again freaky on my part.
 
 my problem still remains intact .as i've told earlier,
 in my ZPT I needed to find a way to sum up column values 
 if they are present and print the total at the last row.
 
 I tried this as a Deepak pal tipped :
 
 span tal:condition=not:penaltylen
 tal:content=python:penalty[0].unit_cost/
 span tal:define=global sum python:sum+penalty[0].unit_cost/
  trtdTotal tdb tal:content=sum/b/td/tr
 
  but what happens is obvious , for reports where even one row has the
 unitcost missing followiing error comes up:
 
 tuple indx out of range
 
 when i changed tghe span tgs alike this :
 
 span tal:condition=not:penaltylen
 tal:content=python:penalty[0].unit_cost
 span tal:define=global sum python:sum+penalty[0].unit_cost/
 /span
 
 no error was there but the total remained 0.
 
 No ZSQLmethod can be used to get the sum coz its pretty complex.
 
  so plz rethink the code I'm also trying hard.
  hope for a reply soon
  
   
 
 On 5/20/05, Deepak [EMAIL PROTECTED] wrote:
 
 
 Hi Prabuddha,

 check this ...
 
 span tal:define=global sum python:0/
 span tal:repeat=item python:here.somesql()
 span tal:condition=item/var tal:define=global sum 
 python:sum+item.var/
 /span
 span tal:content=sum/
 
 thanks,
 
 Deepak
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Re: how to accumulate data using ZPT

2005-05-24 Thread Tino Wildenhain
Am Dienstag, den 24.05.2005, 04:09 -0700 schrieb prabuddha ray:
 sorry,
 i missed the xplanaition.
 i think this'll explain...
 div tal:define= penalty   
 python:context.getPenalty(group_code=gcode,item_code=icode);
  penaltylen python:test(len(penalty)==0)
 
 so not:penaltylen ensures that unit_cost is present for this row.
 
 anyway i think this worked finally :
  td
   span tal:condition=not:penaltylen
   span tal:define=unit_cost python:penalty[0].unit_cost;
 global sum python:sum+unit_cost tal:content=unit_cost/
  /span
 
 tdb tal:content=sum/b/td/tr

Why dont you write this as plain python code?
Python Scripts are made for that.



___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Re: how to accumulate data using ZPT

2005-05-21 Thread prabuddha ray
thanks that was creative and justified. BUT it didnt work.
the total is still 0.

 here is what i did.

div tal:define=unit_cost python:penalty[0].unit_cost; global sum python:0
 tal:condition=not:penaltylen tal:content=unit_cost 
 span tal:define=global sum python:sum+unit_cost/span
  /div
 trtd bTotal
td b tal:replace=sum/b/td/tr

please tip me where I'm going wrong



On 5/20/05, Deepak [EMAIL PROTECTED] wrote:
 
 Hi Prabuddha,

 check this ...
 
 span tal:define=global sum python:0/
 span tal:repeat=item python:here.somesql()
 span tal:condition=item/var tal:define=global sum 
 python:sum+item.var/
 /span
 span tal:content=sum/
 
 thanks,
 
 Deepak
 
 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.
-- 
Share the vision of difference with ME
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Re: how to accumulate data using ZPT

2005-05-21 Thread prabuddha ray
sorry for the last mail. it was a simple tag order mistake .

final version is :
  span tal:condition=not:penaltylen
tal:content=python:penalty[0].unit_cost/
 span tal:define=global sum python:sum+penalty[0].unit_cost/
 trtdbTotal
tdb tal:content=sum/b/td/tr

plz be in touch it'll good for this newbie.
 thanks again

On 5/20/05, prabuddha ray [EMAIL PROTECTED] wrote:
 thanks that was creative and justified. BUT it didnt work.
 the total is still 0.
 
  here is what i did.
 
 div tal:define=unit_cost python:penalty[0].unit_cost; global sum
 python:0
  tal:condition=not:penaltylen tal:content=unit_cost 
  span tal:define=global sum python:sum+unit_cost/span
   /div
  trtd bTotal
 td b tal:replace=sum/b/td/tr
 
 please tip me where I'm going wrong
 
 
 
 On 5/20/05, Deepak [EMAIL PROTECTED] wrote:
  
  Hi Prabuddha,
 
  check this ...
  
  span tal:define=global sum python:0/
  span tal:repeat=item python:here.somesql()
  span tal:condition=item/var tal:define=global sum 
  python:sum+item.var/
  /span
  span tal:content=sum/
  
  thanks,
  
  Deepak
  
  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.
 -- 
 Share the vision of difference with ME
 


-- 
Share the vision of difference with ME
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Re: how to accumulate data using ZPT

2005-05-20 Thread prabuddha ray
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 [EMAIL PROTECTED] wrote:
 Am Freitag, den 20.05.2005, 10:36 +0100 schrieb Hugo Ramos:
  On 5/20/05, Tino Wildenhain [EMAIL PROTECTED] 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 ;)
 
 
 
 


-- 
Share the vision of difference with ME
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Re: how to accumulate data using ZPT

2005-05-20 Thread Chris McDonough
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=V1/div
   div tal:content=Atotal/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 [EMAIL PROTECTED] wrote:
  Am Freitag, den 20.05.2005, 10:36 +0100 schrieb Hugo Ramos:
   On 5/20/05, Tino Wildenhain [EMAIL PROTECTED] 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 ;)
  
  
  
  
 
 

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Re: how to accumulate data using ZPT

2005-05-20 Thread Tino Wildenhain
Am Freitag, den 20.05.2005, 03:54 -0700 schrieb prabuddha ray:
 sorry for delay, 
  but the options you gave are ruled out.
 actually not all the rows in the column have the values.

Which is perfectly met by the if statement. Please read
_my_ post again and to the end.

 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.

No, you definitively dont want that type of algorithm implement in
ZPT. Thats better done in python scripts. The skeleton again 
in my mail. Forget about the count() for a moment.

Regards
Tino
-- 
Tino Wildenhain [EMAIL PROTECTED]

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )