Calling DTML methods from Python
Hi, As part of ongoing Squishdot work I wanted to make things like standard_html_header available to the showMessage DTML method, which is called from a python method in Squishdot.py. Why do I have to include self as follows? return self.showMessage(self, REQUEST=REQUEST [stuff]) I thought self was automatically passed by python. Why is it not in this case? is this the same reasons why you need the following (horrible) DTML: <dtml-call "someFunc(_,REQUEST,[stuff])"> rather than <dtml-call "someFunc([stuff])"> which would be much nicer ;-) cheers, Chris
On more of a ranting rather than a genuine question note, Why does this _horrible_ syntax for calling methods with parameters still have to be used? <dtml-[whatever] "someFunc(_.None,_,[parameters])"> *blech* Chris
I believe this is in the Collector... My guess is that no one has yet figured out a good way to make the client and namespace be passed in automatically. This may not be desirable anyhow, because there may be times when you want to change the client... I've actually done this once or twice. I guess there could be something like <dtml-var fooMethod params="x,y,z">. This is another one of those things that trips up newbies almost universally, so a good solution here could really help... Kevin ----- Original Message ----- From: "Chris Withers" <chrisw@nipltd.com> To: "Zope-Dev Mailing List" <zope-dev@zope.org> Sent: Monday, May 29, 2000 12:32 PM Subject: Re: [Zope-dev] Calling DTML methods from Python
On more of a ranting rather than a genuine question note,
Why does this _horrible_ syntax for calling methods with parameters still have to be used?
<dtml-[whatever] "someFunc(_.None,_,[parameters])">
*blech*
Chris
Kevin Dangoor wrote:
I believe this is in the Collector... My guess is that no one has yet figured out a good way to make the client and namespace be passed in automatically. This may not be desirable anyhow, because there may be times when you want to change the client... I've actually done this once or twice.
Is it just me or is there a lot of confusion between the terms namespace, self, client, and the REQUEST object (which, unlike it's name implies, seems to contain a lot more than stuff relating to the HTTP request, like the RESPONSE object, for example ;-) Perhaps this could be shaken down and then, a first for the Zope community I believe ;-), _documented_ somewhere!!! cheers, Chris PS: what is the client anyway? what exactly is in _? why is the RESPONSE object an attribute of the REQUEST object?!
Is it just me or is there a lot of confusion between the terms namespace, self, client, and the REQUEST object (which, unlike it's name implies, seems to contain a lot more than stuff relating to the HTTP request, like the RESPONSE object, for example ;-)
Perhaps this could be shaken down and then, a first for the Zope community I believe ;-), _documented_ somewhere!!!
Well, as far as I've been able to figure out. But everybody correct me where I get it wrong: When a DTML Document is called from the web, it gets itself as the client argument and a namespace as the second argument. Note that it gets itself twice: first as the standard Python object oriented "self" argument and then as the client argument. I seem to recall there's some magic in there where the the object is wrapped in an acquisition class so that it can do a self.REQUEST, but I'm not sure. Any DTML methods called by the first object get None passed in as the client argument. Importantly, DTML methods do not lookup variables in themselves (i.e. from the Python "self"), but only from the namespace. The original object has been added to the namespace at this point so these called methods are able to access things. An example would be if you had a DTML method called "doit" sitting in a folder next to "standard_html_header". Because doit acquires from its container, you could say "doit.standard_html_header" from Python because standard_html_header is a property of the containing folder. But using "<dtml-var standard_html_header>" from inside doit only works if standard_html_header is available in the namespace. External methods add more fun :-). As noted in the documentation, the enclosing folder will be passed in automatically if you call the first argument "self" (and you pass in yourself one fewer argument than the function calls for). Note this is NOT the standard python object oriented "self" argument, which would be the external method sitting in the ZODB if anything, but the enclosing folder. You do have to call it "self" or you don't get anything. The "self" argument is able to acquire REQUEST so you can say "self.REQUEST", but you don't get a namespace automatically.
participants (3)
-
Andrew Wilcox -
Chris Withers -
Kevin Dangoor