Can't get ZClass baseclass to behave as DTML Method
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
Martijn Faassen wrote:
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__:
[snip]
instead it'll display index_html (that is acquired and not defined on the ZClass). It apparently isn't calling __call__ at all.
Zope checks an object for 'index_html' *before* '__call__', so if your object can acquire one, that's what will get rendered. To prevent that, you can do what the DTML objects do, and set index_html to None. If you *can* do that with a ZClass. Hmm. Well, hopefully, this'll lead you in the right direction.
Evan Simpson wrote:
Zope checks an object for 'index_html' *before* '__call__', so if your object can acquire one, that's what will get rendered. To prevent that, you can do what the DTML objects do, and set index_html to None.
If you *can* do that with a ZClass. Hmm. Well, hopefully, this'll lead you in the right direction.
I'll try and report back to the list. Thanks! Regards, Martijn
Martijn Faassen wrote:
Evan Simpson wrote:
Zope checks an object for 'index_html' *before* '__call__', so if your object can acquire one, that's what will get rendered. To prevent that, you can do what the DTML objects do, and set index_html to None.
If you *can* do that with a ZClass. Hmm. Well, hopefully, this'll lead you in the right direction.
I'll try and report back to the list. Thanks!
It worked! Thanks! You can do it with a ZClass. Apparently you need to call the __call__ arguments exactly like Phillip Eby mentioned in response to an earlier question of mine: def __call__(me, self, REQUEST): ... Thanks Phillip! This does NOT work for some reason: def __call__(self, client, REQUEST): ... Regards, Martijn
participants (2)
-
Evan Simpson -
Martijn Faassen