[Zope-dev] More almost __call__ ;-)
Toby Dickenson
tdickenson@geminidataloggers.com
Fri, 13 Oct 2000 12:56:50 +0100
On Fri, 13 Oct 2000 11:48:39 +0100, Chris Withers <chrisw@nipltd.com>
wrote:
>I have a Python Product Class, with a method, a_method, that gets called
>from some of the Python Product's management screens (encapsulation is
>good ;-)
>
>This method needs several parameters from the namespace, so when it's
>called I was hoping I wouldn't have to do something nasty and clunky
>like:
>
><dtml-var "a_method(param1,param2,param3)">
>
>Given my recently acquired __call__ Zen, I thought 'No problem...' and
>tried to define the method as follows:
>
> isDocTemplate = 1
>
> def a_method(self, ignored=None, md=None):
>
>...with the hope I'd just be able to do <dtml-var a_method> and pluck
>the stuff from md.
>
>No dice.
>
>md and ignored turn up as None from all the <dtml-var a_method> calls.
>:-(
>
>What am I doing wrong? How can I get access to the namespace in a method
>of a class like this?
You need to have the isDocTemplate=1 as an attribute of the method
object itself, not the class that contains the method.
You also need some extra voodoo if you want to call the method
directly from ZPublisher (by including the method name in a url). Here
a link to a wrapper that does it all....
<http://www.zope.org/Members/htrd/howto/FunctionTemplate>
you would use....
def a_method(self,md):
do_stuff_with(md['param1'],md['param2'])
a_method = FunctionTemplate(a_method)
Toby Dickenson
tdickenson@geminidataloggers.com