Add Custom Properties to Portal Document
If you want to add your own properties to a CMF Default content object easily, this is how.
following:
http://cmf.zope.org/Members/tseaver/how_tos/using_scriptable_type_info
using the following script (for a document not a newsitem):
## Script (Python) "addArticle" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=container, id ##title= ## # Parameters: # # container -- the folderish location in which to build the object # # id -- id of the object to be built. # # Get the FactoryDispatcher. product = container.manage_addProduct[ 'CMFDefault' ] # Build the instance. product.addDocument( id ) # Fetch it, wrapped in container. item = getattr( container, id ) # Perform other initialization. #item.setSubject( ( 'South Dakota', ) ) # .... item.manage_addProperty('testp','testpcont','string') # Return it to the type object. return item
creates a property testp
with contents testpcont
on the new document.
then going to the portal_catalog,
adding a field index for testp
and updating the catalog for the doc you just added
will get the contents of the property.
(this is easy, but took too long to figure out)
Unfortunately, I have to handle the updating of this property separate from the script that updates the metadata. But that's not too bad.