Zope Object Contexts and Acquisition
Hi all, I know that this topic has been rolled up several times, but I've only found rather "bad" examples. Imagine a simple site: /folder1 /folder2 /folder3/folder4 We also the method "buildMenu" in the root: <dtml-in expr="objectValues(['Folder'])"> <some output code> </dtml-in> So if we call buildMenu from the root, it works as expected, and renders: folder1 folder2 folder3 But when called from folder1, it renders nothing, since there are no folders. But the question is: Is it possible to tell objectValues that it should perform relative to the "buildMenu" method rather than using the parent object (for example, index_html in folder1?). Of course, having a PARENTS[-1] is a workaround, but not a real solution. Is there a possibility to tell objectValues WITHOUT an absolute reference to something that it should work relative to buildMenu? Best regards, Timo -- Timo A. Hummel, Head of Monday Recordings Monday Recordings Phone : +49 (0)69 460 940 80 P.O. Box 17 05 35 Fax : +49 (0)69 460 940 81 60079 Frankfurt E-Mail: timo@monday-rec.com GERMANY Web : http://www.monday-rec.com
"Timo A. Hummel" wrote:
Hi all,
I know that this topic has been rolled up several times, but I've only found rather "bad" examples. Imagine a simple site:
/folder1 /folder2 /folder3/folder4
We also the method "buildMenu" in the root:
<dtml-in expr="objectValues(['Folder'])"> <some output code> </dtml-in>
try this: <dtml-in expr="getPhysicalRoot().objectValues(['Folder'])"> <some output code> </dtml-in> of course, if you used Python Scripts and ZPT, you probably wouldn't have this problem since they're a bit more clued about the location of themselves by way of the 'container' variable in Python Scripts and the 'script' variable in ZPT. cheers, Chris
<dtml-in expr="getPhysicalRoot().objectValues(['Folder'])"> <some output code> </dtml-in>
This doesn't help, since, for example, the whole directory structure is moved one level down (e.g. into /site1), you had to edit that code again to fit the new requirement (e.g. getPhysicalRoot().site1.objectValues(['Folder']). Best regards Timo
"Timo A. Hummel" wrote:
<dtml-in expr="getPhysicalRoot().objectValues(['Folder'])"> <some output code> </dtml-in>
This doesn't help, since, for example, the whole directory structure is moved one level down (e.g. into /site1), you had to edit that code again to fit the new requirement (e.g. getPhysicalRoot().site1.objectValues(['Folder']).
Sorry, I think you need to explain a bit more abotu what you're trying to achieve... cheers, Chris
<dtml-in expr="getPhysicalRoot().objectValues(['Folder'])"> <some output code> </dtml-in>
When you call the code above in a DTML-Method in your root folder, it lists all the directories in the root. So far so good. Let's say you want to restructure your zope project and move everything from the root into /site1, so you will have these results: /site1/theobjectValuesDTMLMethod /site1/folder1 /site1/folder2 So if you use the code above, it will still list the folders of / and not of /site1. The function objectValues always operates *relative* to from where it was called (so it is the lowest namespace. e.g. if you remove the getPhysicalRoot() in the example above, it would list all folders of /site1/folder1 if /site1/folder1/index_html calls theobjectValuesDTMLMethod) and not relative to the object it is actually called. It would be no difference if the code above is in /site1/theobjectValuesDTMLMethod or in /site1/folder1/index_html since acquisition does that. The most simple example: Just think of the whole example as a unix filesystem and the dtml-in stuff just as regular includes. The "include" /site1/theobjectValuesDTMLMethod would list the contents of /site1 and not of /site1/folder1, altough /site1/theobjectValuesDTMLMethod was called from /site1/folder1/index_html. In Zope, /site1/theobjectValuesDTMLMethod lists the contents of /site1/folder1. Got the point? :) Best regards Timo
"Timo A. Hummel" wrote:
<dtml-in expr="getPhysicalRoot().objectValues(['Folder'])"> <some output code> </dtml-in>
When you call the code above in a DTML-Method in your root folder, it lists all the directories in the root. So far so good. Let's say you want to restructure your zope project and move everything from the root into /site1, so you will have these results:
/site1/theobjectValuesDTMLMethod /site1/folder1 /site1/folder2
Well, if you do this, then you'll want to change getPhysicalRoot() either to site1, if site1 is a unique name, or restrictedTraverse('/site1') if it's not. Incidentally, I have a suspicion that you may not understand acquisition, especially in the context of a Zope 2 application, as fully as you think you do. Be careful, it'll bite you if you're not careful. cheers, Chris
does that do what you want to do? # pyscript listRoot rootPath = context.rootPath root = container.restrictedTraverse(rootPath) objects = root.objectValues(['Folder']) return objects where rootPath is a property i've set on my root folder, with a value of eg. '/site1' or '/' hth peter. On Tue, 26 Feb 2002, Timo A. Hummel wrote:
<dtml-in expr="getPhysicalRoot().objectValues(['Folder'])"> <some output code> </dtml-in>
When you call the code above in a DTML-Method in your root folder, it lists all the directories in the root. So far so good. Let's say you want to restructure your zope project and move everything from the root into /site1, so you will have these results:
/site1/theobjectValuesDTMLMethod /site1/folder1 /site1/folder2
So if you use the code above, it will still list the folders of / and not of /site1. The function objectValues always operates *relative* to from where it was called (so it is the lowest namespace. e.g. if you remove the getPhysicalRoot() in the example above, it would list all folders of /site1/folder1 if /site1/folder1/index_html calls theobjectValuesDTMLMethod) and not relative to the object it is actually called. It would be no difference if the code above is in
/site1/theobjectValuesDTMLMethod
or in
/site1/folder1/index_html
since acquisition does that. The most simple example: Just think of the whole example as a unix filesystem and the dtml-in stuff just as regular includes. The "include" /site1/theobjectValuesDTMLMethod would list the contents of /site1 and not of /site1/folder1, altough /site1/theobjectValuesDTMLMethod was called from /site1/folder1/index_html. In Zope, /site1/theobjectValuesDTMLMethod lists the contents of /site1/folder1.
Got the point? :)
Best regards Timo
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (3)
-
Chris Withers -
Peter Sabaini -
Timo A. Hummel