Creating a Pre-Populated Folder
THIS IS OBSOLETE AND WORKS ONLY WITH PLONE 2.0. This has been kept here as there are useful comments about how to do similiar things with Plone 2.1 and Plone 2.5.
You want to create a new folderish object that is pre-populated with a variety of content objects.
- goto portal_types
- add new
- id: addPopulatedFolder
- title: prepopulated folder
- parameters: container, id
## Script (Python) "addPrePopulatedFolder" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=parent, id ##title=Subject Area ## # First, create an instance of the portal_type most like the # one we want, to allow the instance to be persisted in the ZODB. parent.invokeFactory(id=id, type_name='Folder') # Get a reference to the newly created portal_type object. obj = getattr(parent,id) obj.invokeFactory(id='newsitem_1', type_name='News Item') obj.invokeFactory(id='document_1', type_name='Document') obj.invokeFactory(id='image_1', type_name='Image') # We have just populated it with 3 content objects! # We can nest a few folders; of course nesting Populated Folder # would do bad things # Create folder1 inside of our Populated Folder instance obj.invokeFactory(id='folder1', type_name='Folder') # Get a reference to the newly created folder ... folder1 = getattr(obj, 'folder1') # ... and create a subfolder inside. folder1.invokeFactory(id='subfolder1', type_name='Folder') return obj # It is very important to hand back the object so that # the CMF machinery can imprint some type information onto # the instance. Up to this point, obj is just a Folder. But # when you return it the machinery will make it a Populated # Folder.
In portal_types in the drop down list there is a 'Scriptable Type Information'; add it.
- you only need to fill out two fields:
- id: Populated Folder
- use Default Type Information: CMFPlone: Plone Folder
- now that you've created the type information, click on it to edit it.
- Constructor permission: Add portal content
- Constructor path: portal_types/addPopulatedFolder
- NOTE: the above is the relative path to the portal from where you are adding the object. So anywhere inside a CMF portal you can easily access the portal_types by just traversing to it. This happens via Acquisition.
Now you are done. You should be able to add
Populated Folder instances
to your Folderish objects. If you are using Plone there is one more step
- in portal_properties/site_properties there is a property,
Populated Folderto that list (on a new line).
Why is this? Because Plone attempts to layer functionality on top of CMF instead of completely replacing it. Therefore there are some implementation details (e.g., when something is a folder/object) that are exposed. The tab code is crufty and old but fairly easy to fix (especially if you aren't trying to be all things to all people).