[Zope-CMF] Query portal_catalog for current object?

Jon Edwards jon@pcgs.freeserve.co.uk
Wed, 30 Jan 2002 16:21:19 -0000


> It would be so very very very nice if you could do this:
>
> here.portal_catalog(path={'query': '/'.join(here.getPhysicalPath()),
>                           'depth': 1},
>                     id=here.getId()
>                    )

I think I've found a solution to this, but I'd appreciate any comments :-)

Following Seb's How-To on Subclassing the CatalogTool -
http://cmf.zope.org/Members/seb/CreateCatalogTool/view - I added a
FieldIndex 'parentfolder', then added -

   vars['parentfolder']= '/'.join(object.aq_parent.getPhysicalPath())

- to the catalog_object function.

So now I can do a query like -

here.portal_catalog(parentfolder='/'.join(here.aq_parent.getPhysicalPath()),
                    id=here.getId())

- and should be guaranteed only one result?

Displaying the results is a little cumbersome, cos it will return a list
(with one object in it) - so I ended up using the tal:repeat method round
the code that displays it. Maybe there's a better way?

Hope that helps someone!

Cheers, Jon