pluggablecatalog
Category: Development tools, Miscellaneous
—
Other products by this author
Current release: pluggablecatalog 1.0
Released Jul 24, 2008 — tested with Plone 3.1, Plone 3.0, Plone 2.5
Release of the newly eggified version of Products.pluggablecatalog.
Experimental releases
There are no experimental releases available at the moment.
Project Description
- Project resources
This is the tool's docstring showing one example usage. Using the pluggablecatalog is as simple as defining your own IQueryDefaults utility. More plugin points are planned:
Wraps CMFPlone's CatalogTool to add default parameters
collected from IQueryDefaults utilities.
Install the catalog:
>>> from StringIO import StringIO
>>> from Products.pluggablecatalog.Extensions.install \
... import _replaceCatalog
>>> self.loginAsPortalOwner()
>>> _replaceCatalog(self.portal, StringIO())
>>> self.login()
>>> from Products.pluggablecatalog.tool import CatalogTool
>>> catalog = self.portal.portal_catalog
>>> isinstance(catalog, CatalogTool)
True
We create two documents and make sure they're indexed:
>>> before = len(catalog())
>>> self.folder.invokeFactory('Document', 'doc1')
'doc1'
>>> self.folder.invokeFactory('Document', 'doc2')
'doc2'
>>> doc1, doc2 = self.folder.doc1, self.folder.doc2
>>> doc1.setTitle('First Document')
>>> doc2.setTitle('Second Document')
>>> doc1.reindexObject(); doc2.reindexObject()
>>> len(catalog()) - before
2
Let's now add a rather stupid IQueryDefaults utility that
restricts searches by default to objects with the Title 'First
Document':
>>> from zope import component
>>> from zope import interface
>>> from Products.pluggablecatalog.interfaces import IQueryDefaults
>>> def myDefaults(context, request):
... return {'Title': 'First Document'}
>>> interface.directlyProvides(myDefaults, IQueryDefaults)
>>> component.provideUtility(myDefaults)
With this utility in place, we should only retrieve doc1 now,
unless we explicitly provide a 'Title' query parameter:
>>> len(catalog())
1
>>> catalog()[0].getObject().aq_base is doc1.aq_base
True
>>> len(catalog(Title='Second Document'))
1
>>> (catalog(Title='Second Document')[0].getObject().aq_base is
... doc2.aq_base)
True