Re: [Zope] Indirect calling of extensions?
Glenn Rogers <zope-list@gacela.demon.co.uk> wrote:
Imagine I have a python extension, with zope id pyFetch
def Fetch (self, href): ...
I want to call this in a manner similar to:
<!--#let call_method="'pyFetch'"--> <!--#in sql-method-returns-href--> <!--#var "_[call_method]( href )"--> <!--#/in--> <!--#/let-->
But I get an error:
Error Type: TypeError Error Value: not enough arguments; expected 2, got 0
So it seems to evaluate and call the extension without adding the parameters. I guess I need something like lambda in python.
Can anyone help me please?
I don't know what you mean by "python extension" -- is this an ExternalMethod? A PythonMethod (it doesn't look like one)? A method of a class defined in a Python product (I don't see an instance anywhere)? I'll assume an ExternalMethod, because it looks most like your stuff. Assuming you have a folder, which contains/acquires an ExternalMethod, 'pyFetch', defined as taking two parameters, as above (I'm assuming from your description that you have the EM with a different ID than its underlying function -- that works, but for clarity I would generally avoid that). This folder contains/acquires some method, 'list_hrefs', which returns a list of objects which have an attribute, href. In a DTML method contained/acquired by that folder:: # I'm using a PythonMethod which returns a list of dicts, # so I am using the 'mapping' argument to get its key/values to # look like attributes. <ul> <dtml-in list_hrefs mapping> <li><dtml-var "this().pyFetch( href )"></li> </dtml-in> </ul> That works for me -- I get an unordered list of the results of calling pyFetch() on each href "attribute". -- ========================================================= Tres Seaver tseaver@palladion.com 713-523-6582 Palladion Software http://www.palladion.com
On Fri, Mar 24, 2000 at 03:28:09PM -0600, Tres Seaver wrote:
Glenn Rogers <zope-list@gacela.demon.co.uk> wrote:
Imagine I have a python extension, with zope id pyFetch
def Fetch (self, href): ...
I want to call this in a manner similar to:
<!--#let call_method="'pyFetch'"--> <!--#in sql-method-returns-href--> <!--#var "_[call_method]( href )"--> <!--#/in--> <!--#/let-->
I don't know what you mean by "python extension" -- is this an ExternalMethod?
Yes. It lives in the zope extensions directory though - blame lack of sleep.
In a DTML method contained/acquired by that folder::
<ul> <dtml-in list_hrefs mapping> <li><dtml-var "this().pyFetch( href )"></li> </dtml-in> </ul>
Problem: In real life, I don't know that I'm calling pyFetch, it could be pyDontFetch or pyGoToSleep etc (the "#let call_method" is in another DTML method and there are a few alternatives). All I know is that it shares the same signature. Works fine if you call it directly. Is there a better method than the equivalent of <!--#if "call_method=='pyFetch'"--> <!--#var pyFetch( href )--> <!--#elif "call_method=='pyDontFetch'"--> <!--#var pyDontFetch( href )--> ... Thanks Glenn
participants (2)
-
Glenn Rogers -
Tres Seaver