[Zope-dev] ZClasses as *methods*

Martijn Faassen m.faassen@vet.uu.nl
Wed, 25 Aug 1999 14:44:55 +0200


Hi there,

For a while now I've been trying to accomplish the following with
ZClasses:

I have a ZClass called 'Router'. This ZClass should call DTML Methods
dependent on a variable in REQUEST. The simplest case of what I'd like
is that Router goes into DTML Method 'Foo' if there's a request variable
called 'hoi', and otherwise it goes into DTML Method 'Bar'.

The tricky bit is that I want the Router object to behave the same as a
DTML Method in the respect that it also should be a member function of
the folder, not an object by itself. This way it can be acquired like
DTML methods, and I can build a structure consisting of DTML methods and
Routers, for instance to transform an XMLDocument into HTML.

What the Routers would do is in this case is transform some parts of the
XML tree differently dependent on a variable in REQUEST. For instance, I
could have a request variable 'focus' set to an id in an XML Document
(for instance 'e1'). Then, during the rendering of 'e1', the Router
object sees 'Focus' is set to that value, and reacts by calling a
different rendering method (that for instance colors text purple so that
the element is displayed in purple in the resulting HTML).

But, I can't seem to be able to write a ZClass that does this. I try
inheriting from a Python base class and overriding __call__, but the
resulting objects don't behave like DTML Methods -- 'self' becomes the
instance of that object, instead of the XML Document I'm working on,
like it is with DTML Methods.

So, what makes DTML Methods special? Am I going about the right route at
all? Any suggestions at all would be very welcome.

Regards,

Martijn