ZClasses as *methods*
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
At 02:44 PM 8/25/99 +0200, Martijn Faassen wrote:
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.
Try making your __call__ signature: def __call__(me,self,...): And use 'me' to refer to the instance, self to refer to the object called with. Alternatively, just use REQUEST.PARENTS[0] to refer to the object you're a method of. See the DTML User's Guide. (This only works if the method is called from the web, though.)
On Wed, 25 Aug 1999, Phillip J. Eby wrote:
Try making your __call__ signature:
def __call__(me,self,...):
And use 'me' to refer to the instance, self to refer to the object called with. Alternativly, he probably could use this hack (this is what ZOPE basically does, and it worked with Bobo, if I recall correctly):
class Base: pass def method(self,...): pass Base.__call__=method Andreas -- Andreas Kostyrka | andreas@mtg.co.at phone: +43/1/7070750 | phone: +43/676/4091256 MTG Handelsges.m.b.H. | fax: +43/1/7065299 Raiffeisenstr. 16/9 | 2320 Zwoelfaxing AUSTRIA
participants (3)
-
Andreas Kostyrka -
Martijn Faassen -
Phillip J. Eby