Using external python functions from TAL
I have been playing around with TAL, and external python products. I have no problem calling external python methods on an object using the root namespace variable "here". as in : <td tal:content="python:here.foo("></td> or on some other object that I find through that root. as in: <tr tal:repeat="object python:here.getObhectsList()"> <td tal:content="python:object.foo"></td> </tr> But I have no idea how to access a random function that is not an object method. For example, I would like to be able to have a module called MyProduct.Functions, containing a function foo(), and call it like this: <td tal:content="python:MyProduct.Functions.foo()"></td> How do I get access to this name space?
Sean Hastings wrote at 2003-6-5 13:34 -0400:
... I have been playing around with TAL, and external python products. I have no problem calling external python methods on an object using the root namespace variable "here". as in :
<td tal:content="python:here.foo("></td>
or on some other object that I find through that root. as in:
<tr tal:repeat="object python:here.getObhectsList()"> <td tal:content="python:object.foo"></td> </tr>
But I have no idea how to access a random function that is not an object method.
For example, I would like to be able to have a module called MyProduct.Functions, containing a function foo(), and call it like this:
<td tal:content="python:MyProduct.Functions.foo()"></td>
I am not sure, I understand your problem fully. The namespace of External Methods is somehow flat. There are no modules of External Methods. However, you can collect and organized External Methods in Zope "Folder" objects. Suppose, you have a "Folder" "MyFunctions" which contains the External Method "Function", then you can access it as: <td tal:content="python: here.MyFunctions.Function()"> The magical passing of "self" will probably no longer give the expected result. You will probably need to pass "self" explicitely (when your External Method needs this "self"). This would look somehow like: <td tal:content="python: here.MyFunctions.Function(here,...)"> The access chain to your External Method can be arbitrary long. Dieter
Sean Hastings wrote:
<td tal:content="python:MyProduct.Functions.foo()"></td>
How do I get access to this name space?
Have a look at the Products/PythonSripts/standard.py security declarations. Then have a look at the examples of usign module functions, I think they're in the Zope Book somewhere in the ZPT section... cheers, Chris
participants (3)
-
Chris Withers -
Dieter Maurer -
Sean Hastings