[Zope] How do I count children?

Kapil Thangavelu kvthan@wm.edu
Thu, 03 Aug 2000 06:33:52 -0700


"J. Atwood" wrote:
> 
> So In ZUBB (my discussion product) I want to be able to show how many
> replies there have been to any one main topic. All replies are 'children' of
> the main post and when I state it with
> 
> <dtml-tree branches=children>
>     Stuff
> </dtml-tree>
> 
> It works and knows that each message is a child of the message.
> 
> When in go through a searchResult to list the message I want to  show many
> replies there are to that message.
> 
> Q: How do I count the 'children' of any one onject?



if children aren't nested
<dtml-let x="objectIds(['childrenClass'])">
<dtml-var "_.len(x)">
</dtml-let>

if children are nested you probably need a recursive dtml/python method.

in python 

def count_children(o):
	x = o.objectItems(['childClass'])	
	sum = len(x)
	for child, child_name in x:
		sum = sum + count_children(child)
	return sum


Kapil