Getting Properties of Objects in Folders Within Catalog Results
I am using the following script to get objects out of the catalog: objects = [] results = [] for object in context.Catalog(meta_type='Folder'):results.append(object) print results return results And I recieve the following results: [<mybrains instance at 22E275B0>, <mybrains instance at 14AEC958> ]However, I would like to get information about objects within each of the folders that are returned (such as the id and description of images that are contained in the folders). I know this information would not be part of each folder's entry in the catalog, but can it be obtained through aquisition -- perhaps if I know the path to the object? Can this be done using a python script to query the catalog, and then dtml to access the namespace for each folder? Thanks in advance, John T.
John Tynan wrote:
I am using the following script to get objects out of the catalog:
objects = [] results = []
for object in context.Catalog(meta_type='Folder'):results.append(object) print results return results
And I recieve the following results:
[<mybrains instance at 22E275B0>, <mybrains instance at 14AEC958> ]
However, I would like to get information about objects within each of the folders that are returned (such as the id and description of images that are contained in the folders).
I know this information would not be part of each folder's entry in the catalog, but can it be obtained through aquisition -- perhaps if I know the path to the object?
Can this be done using a python script to query the catalog, and then dtml to access the namespace for each folder?
The getObject method on 'mybrains' will give you a handle to the object itself, which should be just as good as getting it through any other method. Note that you are waking up the objects when you do this. The alternate nasty way is to use restrictedTraverse on the path metadata on each object. --jcc -- "Building Websites with Plone" http://plonebook.packtpub.com/
----- Original Message ----- From: "J Cameron Cooper" <zope-l@jcameroncooper.com> To: "John Tynan" <john.tynan@riomail.maricopa.edu> Cc: <zope@zope.org> Sent: February 3, 2005 5:19 PM Subject: Re: [Zope] Getting Properties of Objects in Folders Within CatalogResults
John Tynan wrote:
I am using the following script to get objects out of the catalog:
objects = [] results = []
for object in context.Catalog(meta_type='Folder'):results.append(object) print results return results
And I recieve the following results:
[<mybrains instance at 22E275B0>, <mybrains instance at 14AEC958> ]
However, I would like to get information about objects within each of the folders that are returned (such as the id and description of images that are contained in the folders).
I know this information would not be part of each folder's entry in the catalog, but can it be obtained through aquisition -- perhaps if I know the path to the object?
Can this be done using a python script to query the catalog, and then dtml to access the namespace for each folder?
The getObject method on 'mybrains' will give you a handle to the object itself, which should be just as good as getting it through any other method.
Note that you are waking up the objects when you do this.
The alternate nasty way is to use restrictedTraverse on the path metadata on each object.
if you have meta data set up then you don't need restrictedTraverse, you can just: results = context.Catalog(...) for aresult in results: print aresult.metafieldA print aresult.metafieldB You only need restrictedTraverse (or alternately, getObject) if you need to access fields in the object which are not stored in the catalog (all meta data fields are stored in the catalog, so the expensive access to the object is not required). Jonathan
J Cameron Cooper wrote:
However, I would like to get information about objects within each of the folders that are returned (such as the id and description of images that are contained in the folders).
The getObject method on 'mybrains' will give you a handle to the object itself, which should be just as good as getting it through any other method.
Note that you are waking up the objects when you do this.
The alternate nasty way is to use restrictedTraverse on the path metadata on each object.
You can get the information you need working only in the catalog, by using the getPath() method of the brain. (untested naturally) results = [] for brain in catalog(meta_type='Folder'): print brain.Title path = brain.getPath() # this should get you every catalogued object in the folder for subbrain in catalog(path=path): print subbrain.Title print subbrain.Description This will return all you catalogued content, so you might want to narrow your search a bit. -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science
participants (4)
-
J Cameron Cooper -
John Tynan -
Jonathan Hobbs -
Max M