[Zope-dev] Making Folders callable

Steve Alexander steve@cat-box.net
Fri, 14 Jul 2000 21:48:46 +0100


Is there any reason that Folders aren't callable?

That is, you can't directly render a folder with <dtml-var
nameofafolder>. You have to do something like <dtml-var
"nameofafolder.index_html(_.None, _)">. But, that's not quite the same
because if the folder lacks an index_html, it gets acquired.

Here's an extra method that can be added to lib/python/OFS/Folder.py, or
to ObjectManager.py, to make Folders render nicely.

    # XXX hack to make folders render
    #     retains compatibility with current behaviour
    #     if the folder doesn't contain index_html
    def __call__(self, *args, **kw):
        """ mandatory docstring """
        index = self._getOb('index_html', default=None)
        if index is not None:
            args = (self,) + tuple(args[1:])
            return apply(index, args, kw)
        return ''

Is this a good idea? Should this go into the Collector as an RFE with
patch?

Actually, I'm not sure why it should be tuple(args[1:]) -- I just copied
that out of ZCallable in the latest PTK CVS. I'd guess you'd want to
check the first argument (client) for whether it is None before
replacing it with self.

Perhaps something like this:

  args = (len(args)>0 and args[0] or self,) + tuple(args[1:])

Discussion welcomed.

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net