[Zope] Boolean dtml redux

ethan mindlace fremen mindlace@digicool.com
Mon, 09 Jul 2001 13:32:01 -0400


Leigh Ann Hildebrand wrote:

> ---- "Steve Drees" <drees@the-bridge.net> wrote:
> 
>>ugh.
>>this looks like a good place for a python script.
>>
> 
> I get that a lot. I don't do python yet! I'm trying to work in dtml only,
> though I know it's getting harder and harder. 


look. Get Python Scripts installed. If necessary, get "learning python" 
(book w/mouse on cover).

DTML is *much harder* than python for logic.

In that spirit, I give you 7 lines in python that will do what you want:

# let's get a list of the objects here.
obj_list=context.objectValues()
# we'll go through the list by counting
# up to its length.

for index in range(len(obj_list)):

     # if we're past the end of the shortened list, we're done.
     if len(obj_list) >= index: break
     # let's get it out of it's wrapper
     only_object = obj_list[index].aq_explicit
     # delete it if it's hidden
     if getattr(only_object, 'index_hide', None):
        del obj_list[index]
# give me the list back
return obj_list

I tested this, it should work. Put it in the root of your zope as a 
python script called filteredItems and then you can just dtml-in over it 
like so:

<dtml-in  filteredItems>
<dtml-var sequence-item>
</dtml-in>

You will like zope much more if you use the twin power of python scripts 
and page templates, IMNSHO.

~ethan
Zopatista Community Liason/Prostelytizer :)