[Zope-dev] newbie / dtml-tree and external methods

Gilles Verley gilles@phgroup.com
Fri, 02 Jun 2000 13:51:50 +0200


Hi all, I'm newbie both in python and in zope (in English too!), and 
here is a problem I realy can't sort out.

I would to display the tree structure of a repository disk.
Therefore I wrote a recursive class MyFolder, with the following 
attributes (code is at the bottom of the message):
class MyFolder:
   fname : name of the base folder
   subfolders : a list of MyFolder objects, made after the subfolders 
of my folder
   MyFiles : a list of the files of my folder (actually a list of 
object whose only attribute is the name of the file)


I call this class with the following external method:

def ZMyWalk(self,dir): #=None):

    """ returns ..."""
    # MyRepTest is the default value
    #if not dir : dir=MyRepTest
    return MyFolder(dir)


And I try to publish it with the following DTML-method:

<dtml-with "ZMyWalk('\\\\saigon\\d\\divers\\wlk')">
<dtml-tree branches_expr=subfolders>
  <dtml-var FolderName>
  <dtml-in MyFiles>
     <dtml-var name><br>
  </dtml-in> 
</dtml-tree>
</dtml-with>


It displays the first level fine. But when I try to expand the tree
by 
clicking on the small + sign, it acts randomly (doesn't do anything, 
or expand another branch, sometimes it even does the right thing, ..).

Any guess? I'm totally lost :-( . I'm not sure I does this the right 
way. The SomeFile class I 've made seem rather artificial.
I run Zope 2.1.6 with Python 1.5.2 under NT4.0 and I got the 
TreeTag.py pach.



PS : here are the classes I use.


class MyFolder:

    """fait une recursion dans un repertoire"""

    def __init__(self,dir):
        self.path=dir
        self.FolderName=os.path.basename(dir)
        self.subfolders=[]
        self.MyFiles=[]
        for f in os.listdir(dir):
            pathname='%s\\%s' % (dir, f)
            if os.path.isdir(pathname):
                self.subfolders.append(MyFolder(pathname))
            elif os.path.isfile(pathname):
                self.MyFiles.append(SomeFile(f))
            else:
                pass

        
class SomeFile:

    """ ... """
    def __init__(self,name):
        self.name=name