You are not logged in Log in Join
You are here: Home » Download Zope Products » Content Management Framework » CMF Documentation » Developing for CMF » How-to: Using 'Scriptable Type Information' type objects » View Document

Log in
Name

Password

 

How-to: Using 'Scriptable Type Information' type objects

The standard type objects created when a CMF Site is generated

Overview

The type objects added to the portal_types tool during the generation of a stock CMF Site are instances of the FactoryTypeInformation class: they adapt Zope's standard product/factory mechanism to the interface expected by the portal_types tool, providing easy setup in exchange for minimal control over the construction process.

The alternative type object class, ScriptableTypeInformation, allows the site manager to exert greater control over the construction process by writing a script to do the actual construction and initial configuration of the new instance.

This howto describes setting up an alternative content type, based on News Item, which supplies some initial metadata.

Procedure

  1. In the portal_types tool, select "Scriptable type information" from the add list. Select "CMFDefault.NewsItem" from the "Default type information" dropdown (this supplies default initial values for the type object's properties and actions). Supply an ID for the type object, e.g., MyNewsItem.
  2. Configure the properties for the new type object:
    Title
    My News Item
    Description
    Customized news item.
    Constructor permission
    Add portal content
    Constructor path (see step 3)
    addMyNewsItem
  3. Build a PythonScript, addMyNewsItem, which creates the object in the appropriate container, and then initializes metadata:
       # 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.addNewsItem( id )
    
       # Fetch it, wrapped in container.
       item = getattr( container, id )
    
       # Perform other initialization.
       item.setSubject( ( 'myType', ) )
    
       # ....
    
       # Return it to the type object.
       return item
    
  4. You should now be able to add "My News Item" instances via the "Folder Contents" view.

Hope that helped!