[Zope] Problems looping through Folders and Documents

Jeff Rush Jeff Rush" <jrush@timecastle.net
Tue, 09 Nov 99 07:57:09 -0500


On Tue, 09 Nov 1999 00:53:36 -0700, Adrian Esteban Madrid wrote:

>I want to have two different menues: one with the Folders in the current
>folder and another with the DTML Documents again in the current folder.

Here is my cut at the project.  Instead of explicitly searching for meta_type
'Folder' and 'DTML Document', I used the 'isPrincipiaFolderish' method
to distinguish.  This allows things like ZCatalogs and such to count as
folders, since they -can- contain things like folders.

<dtml-call "REQUEST.set('fobjs', [])"> <!-- Folder Objects -->
<dtml-call "REQUEST.set('dobjs', [])"> <!-- Document Objects -->

<dtml-in "PARENTS[0].objectValues()">
  <dtml-let item="_.getitem('sequence-item', 0)">  <!-- we want ref to obj, _not_ rendered form -->
    <dtml-if "item.isPrincipiaFolderish">
      <dtml-call "fobjs.insert(0, item)">
    <dtml-else>
      <dtml-call "dobjs.insert(0, item)">
    </dtml-if>
  </dtml-let>
<dtml-else>
  No Objects Found
</dtml-in>

Found <dtml-var "_.len(fobjs)"> folders and
<dtml-var "_.len(dobjs)"> documents. <BR>

<dtml-in fobjs>
  Folder <dtml-var "_.getitem('sequence-item', 0).id"> <BR>
</dtml-in>

<!-- The following is tricky because if you just reference 'id', for some
types of objects it is a method and for others, it is a string.  You would
have to test for isCallable or arrange for Zope to do that call for you,
hence the dtml-with wrapper I use.
-->

<dtml-in dobjs>
  <dtml-with "_.getitem('sequence-item', 0)"> <!-- we want ref to obj, _not_ rendered form -->
    Document <dtml-var id> <BR>
  </dtml-with>
</dtml-in>

>This works just great for the first objetive. Unfortunately, I try doing
>the same thing for a second time only with 'DTML Document' but it just
>loops forever (a Python thread uses up 99% of the CPU). I don't know.

When playing with your example, I saw this behavior too.  It seems to
be the extra evaluation of the doc objects, which is avoided by using
.getitem(aname, 0).

-Jeff Rush