[Zope] Factory-based Type Information

J Cameron Cooper zope-l at jcameroncooper.com
Tue Jun 21 13:27:50 EDT 2005


Denis Mishunoff wrote:

> I have a problem with my product.
> I use Zope 2.7.5 and Plone 2.0.5.
> 
> I need to create the copy of Document content-type on my product's
> install the same way as it is done in portal_types via
> "Factory-based Type Information" option of dropdown.
> I just need to have the copy of it and to alter some fields.

Here's some code I stole from Chapter 8 of my book, were a 
Folder-derived type is created in an install script::

   from Products.CMFCore.Expression import Expression

   # Customize types
   types_tool=getToolByName(portal,'portal_types')

   # New 'NewsFolder' type based on folder
   types_tool.manage_addTypeInformation(id='NewsFolder',
                        add_meta_type="Factory-based Type Information",
                        typeinfo_name="CMFPlone: Plone Folder")
   nf = getattr(types_tool, 'NewsFolder')
   nf.manage_changeProperties(filter_content_types=1,
                            allowed_content_types=('News Item',))
   actions=nf._cloneActions()
   for a in actions:
       if a.id == 'view':
           a.action = Expression('string:${object_url}/newsfolder_view')
   nf._actions=(actions)

After a clone of the type is made based on Plone Folder, some changes 
are made: contents are filtered, and only News Items are allowed; also 
an action is changed to point to a custom template.

This is a better option than using the copy/paste API like you might do 
in the ZMI.

		--jcc

-- 
"Building Websites with Plone"
http://plonebook.packtpub.com/

Enfold Systems, LLC
http://www.enfoldsystems.com


More information about the Zope mailing list