Calling a DTML Method from Python
Hi there, I'm attempting to write a product that calls a DTML method during its processing. The product keeps a table of DTML method objects and has a method that determines what DTML method to call, and then calls it. I'm not sure _how_ I should call a DTML method object, though. Example: class Foo: def __init__(self): self.map = {} def setMap(self, keyword, method): self.map[keyword] = method def render(self, keyword): return self.map[keyword]() # ?? What arguments are needed? Then, from DTML: <dtml-call "foo.setMap('hey', somemethod)"> ... <dtml-var "foo.render('hey')"> Is this possible at all? I assume render() actually needs extra arguments to make this work, but which? The DTML Method source defines this: def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw): What does the client argument stand for? Anything else I should watch out for? I keep running into mysteries like this continuously, it seems... Regards, Martijn
At 15:58 08/09/99 , Martijn Faassen wrote:
Hi there,
I'm attempting to write a product that calls a DTML method during its processing. The product keeps a table of DTML method objects and has a method that determines what DTML method to call, and then calls it. I'm not sure _how_ I should call a DTML method object, though.
Example:
class Foo: def __init__(self): self.map = {}
def setMap(self, keyword, method): self.map[keyword] = method
def render(self, keyword): return self.map[keyword]() # ?? What arguments are needed?
Then, from DTML: <dtml-call "foo.setMap('hey', somemethod)"> ... <dtml-var "foo.render('hey')">
Is this possible at all? I assume render() actually needs extra arguments to make this work, but which?
The DTML Method source defines this:
def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
What does the client argument stand for? Anything else I should watch out for?
Client is the namespace object. See the DocumentTemplate.DT_String.String.__call__ method for more information. Don't you love deep inheritance? -- Martijn Pieters, Web Developer | Antraciet http://www.antraciet.nl | Tel: +31-35-7502100 Fax: +31-35-7502111 | mailto:mj@antraciet.nl http://www.antraciet.nl/~mj | PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149 ------------------------------------------
Martijn Faassen wrote:
Then, from DTML: <dtml-call "foo.setMap('hey', somemethod)"> ... <dtml-var "foo.render('hey')">
Is this possible at all? I assume render() actually needs extra arguments to make this work, but which?
The DTML Method source defines this:
def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
What does the client argument stand for? Anything else I should watch out for?
1. Will your DTML Methods try to acquire anything? Normally, a DTML Method's 'client' is its acquisition parent (I think). If you don't care, use None, otherwise pass '_' or 'this()' through a parameter of render. 2. Do they care about form/environment variables or "REQUEST.set(..." stuff? If so, pass REQUEST through render, otherwise omit it from the call. 3. Do you want to intercept RESPONSE redirections, etc.? If so, pass your own object as RESPONSE, otherwise the method should grab it from REQUEST (unless you didn't pass REQUEST <wink>).
participants (3)
-
Evan Simpson -
Martijn Faassen -
Martijn Pieters