[Zope] re: Length of results set
Ken
ken@p11.org
Fri, 17 Jan 2003 11:35:10 +0100 (CET)
>> How do you get the length of results for a <dtml-if> inside a <dtml-in> ?
Dieter Maurer wrote:
> You do *NOT* do this in DTML!
>
> In Python, you simple count all positive hits in a loop:
>
> i= 0
> for o in context.objectValues():
> if ...: i+= 1
> return i
>
> You see, how easy it is in Python?
Dieter, you make it *look* easy!
If DTML is considered scripting and Python programming, why do some say that DTML is harder than Python? I am comfortable with the verbosity - some call it ugliness - of DTML. Of course the expression above is more elegant than its equivalent in DTML, could someone give me an idea of the 'cost differential' between this and the solution below proposed by Dylan Reinhardt?
> <dtml-call "REQUEST.set('my_result', [])">
> <dtml-in objectValues>
> <dtml-if "id==something">
> <dtml-call "my_result.append(something)">
> </dtml-if>
> </dtml-in>
Maybe I persist with DTML and overlook its 'ugliness' because I find DTML embedding convenient as opposed to the combination of Script (Python) + ZPT. I promise to advance with Python, but I vote to keep DTML!
Ken