[Zope-dev] Got "expand_all" to work in a tree tag with leaves

Andrew Wilcox circle@gwi.net
Thu, 18 Nov 1999 18:25:47 -0500


I've been battling the tree tag all day to get expand_all to work, and it
almost won, but then I hacked the source.  {insert evil manical laughter here}

Simple use of the tree tag, listing the titles of objects within folders:

    <!--#var standard_html_header-->
    <p><a href="<dtml-var URL0>?expand_all=1">Expand all</a></p>
    <!--#tree myfolder leaves=listObjects-->
      <!--#var title_or_id-->
    <!--#/tree-->
    <!--#var standard_html_footer-->

Where listObjects is a simple DTML Method that lists the titles of the
objects within the folder, with a little indenting:

    <!--#var standard_html_header-->
    <p><dtml-in "objectValues()">
      <dtml-if "_['sequence-index'] != 0"><br></dtml-if>
      &nbsp;&nbsp;&nbsp;&nbsp;<dtml-var title_or_id>
    </dtml-in>
    <!--#var standard_html_footer-->

Now, if you hit the "expand all", it expands all the folders except those
at the lowest level, the ones that just contain (non-folder) objects.

My first thought was that maybe it wasn't really considering the lowest
level folders to be a branch, so I spent a while trying different functions
for the "branches" attribute.  That didn't work.

Take a look at tpValuesId inside of TreeTag.py, which builds a list of all
the expandable subitems for expand_all:

        try: items=getattr(self, branches)()
        except AttributeError: items=()
        for item in items:
            try:
                if getattr(item, branches)():

If I'm reading this right, the first call on branches gets the subitems
which are considered a branch (defaulting to isPrincipiaFolderish over in
ObjectManager).  But then the second call on branches checks if the subitem
itself has a non-zero number of branches.  I commented out the second call
there, and lo and behold!  Suddenly my tree was fully expanding.

So, what did I break?  :)

Andrew