Fun Fact of the Day
written by Ian McCracken
at Monday, March 31, 2008
So, let's say you're trying to catalog an object in a ZCatalog, and for important reasons irrelevant to the instant case you have code similar to the following:
I sure assumed that would work. Not so! If the catalog is empty,
And there's an hour I'll never get back.
from Products.CMFCore.utils import getToolByName
def _getCatalog():
try:
return getToolByName(context, 'my_catalog')
except AttributeError:
return None
catalog = _getCatalog()
if catalog:
catalog.catalog_object(myobject)
I sure assumed that would work. Not so! If the catalog is empty,
bool(catalog)==False
. You have to do:
if catalog is not None:
And there's an hour I'll never get back.