[Zope] Acquisition not working as expected

Roman Klesel roman_plonemail at lotuseyes.de
Fri Mar 3 03:12:10 EST 2006


Andrew Milton schrieb:
> 
> Perhaps if you describe the problem you're trying to solve, we can actually
> help you.
> 

Yes, thank you!

I just want to be able to do what I'm used to do from TTW:

- There is a hirarchy of Folder/File objects
- In the root directory there is an python script (showData.py)
- the python script operates on context eg.

return context.data

>From a ZPT I can now loop over a Folder and call the python script on every object in the folder:

<ul>
 <li tal:repeat="elem context/objectValues"
     tal:content="elem/showData">data</li>
<ul>

Depending on the URL I call this on I will get a list of data of all files present here.

This is just what I want to do in the fs product I'm writing:

I have a folderish object that holds a collection of File objects nicely sorted in a hirarchy of Folders objects.
This folderish object has methods to display the data in the File objects (underneth it self) in differnt ways eg.

def genGraph(self):
    "plot graph from self.data and return a png image"
...

def getDataMatrix(self):
    "return self.data as a list of rows where every field is a list element"
...

just as in my example above I want to be able to call this methods on any File objects from a ZPT like this:

<ul>
 <li tal:repeat="elem context/objectValues"
  <img tal:attributes="src string: ${elem/absolute_url}/genGraph"> plot </img>
 </li>
<ul>

Therefore I started the thread:
[Zope] context in fs product

The answer I got:

'self' inside the a Zope product is the _same_ as 'context' or 'here' within
ZPT or PythonScripts.

So now I'm stuck.

Of course I could pass the object or its id to the methods as an argument eg.

<span tal:define="data python:context.genGraphs(elem)">sdf</span>

and in the method get the the object with getattr() or something ...

But this wouldn't be nearly as nice and I'd like to avoid this.


(The code examples here might have errors, I just typed them in as an illustration of my thougts)

Greetings Roman




More information about the Zope mailing list