[Zope] Getting Properties of Objects in Folders Within CatalogResults

Jonathan Hobbs toolkit at magma.ca
Thu Feb 3 17:59:36 EST 2005


----- Original Message -----
From: "J Cameron Cooper" <zope-l at jcameroncooper.com>
To: "John Tynan" <john.tynan at riomail.maricopa.edu>
Cc: <zope at 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







More information about the Zope mailing list