[Zope] Indirect calling of extensions?

Tres Seaver tseaver@palladion.com
Fri, 24 Mar 2000 15:28:09 -0600


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