[Zope-dev] Can't get ZClass baseclass to behave as DTML Method

Martijn Faassen m.faassen@vet.uu.nl
Wed, 08 Sep 1999 17:44:30 +0200


Hi there again,

Python and DTML Methods, one way or another they seem to be the theme
for me today..

A couple of weeks ago I asked the same question (I encountered it in
different circumstances). I'm trying to create a ZClass (deriving from a
Python base class) that behaves like a DTML _method_.

To this purpose, I tried to define this __call__:

def __call__(self, client, REQUEST=None):
    "Call this ZClass as a DTML method."
    return self.render(client, REQUEST)

in the base class that is inherited by a ZClass.

If I grok the answers I got today by Martijn Pieters and Evan Simpson
right, the arguments mean the following:

self - the instance of this ZClass
client - the object we're calling this method on (in my case an XML
node)
REQUEST - the regular request object

the 'render' function figures out how to display the node (client) and
returns the resulting string.

This is however not working -- if I call an instance 'foo' like this on
an XML node, like this:

xmldoc/e7/e14/foo

instead it'll display index_html (that is acquired and not defined on
the ZClass). It apparently isn't calling __call__ at all.

How do I fix that? Do I have to go full fledged product to do this? I'd
like to use ZClasses because it's easier, but perhaps they simply don't
allow it?

Once I get this working I'll go back to the calling DTML Methods from
Python problem again. :)

Regards,

Martijn