[Zope] How to search for empty properties in ZCatalog - nifty solution
Itamar Shtull-Trauring
itamars@ibm.net
Wed, 29 Dec 1999 15:33:04 +0200
The following python method returns a list of all the empty properties in
the ZClass it's a method of. Add it as a KeywordIndex to your ZCatalog, and
you can search for empty properties easily.
For example, if you want to find all object where 'title' is empty, use:
<dtml-in "catalog({'emptyProperties' : 'title'})">
...
</dtml-in>
================================================================
# ** function name: emptyProperties
# ** parameters: self
## Return list of all empty properties in our propertysheets
##
emptyproperties = [] #empty properties
propertysheets = self.propertysheets.items()
i = 0
for sheetname in propertysheets:
sheetname = sheetname[0]
if sheetname == 'webdav':
i = i + 1
continue
psheet = self.propertysheets[i]
validprops = []
for pmap in psheet.propertyMap():
if pmap['type'] in ['string', 'text']: validprops.append(pmap['id'])
for pname, pcontent in psheet.propertyItems():
if (pname in validprops) and (not pcontent): emptyproperties.append(pname)
i = i +1
return emptyproperties