|
From: alan r. <ru...@ru...> - 2003-02-26 04:21:22
|
someone was asking how to make a pre-populated folder
through-the-web. here is a howto. I would appreciate it going into FAQ
and maybe Book? If someone would like to
post it into Zopelabs that would be great.
~runyaga
Scriptable Type Information
You want to create a new folderish object
that is pre-populated with a variety of content
objects.
in ZMI:
- goto portal_types
- add new (Script) Python
- id: addPopulatedFolder
- title: prepopulated folder
- parameters: container, id
<code>
context.invokeFactory(id=id, type_name='Populated Folder')
#create a new instance of your portal_type in the the
#current context
obj=getattr(context,id)
#get a reference to the newly created portal_type object
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 are creating 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')
#we nest a few folders; of course nesting Populated Folder would do bad
things
return obj
#very important we must hand back the object so that
#the CMF machinery can imprint some type information onto
#the instance
</code>
- in portal_types in the drop down list there is a 'Scriptable Type
Information'; add it.
- the only things you need to fill out are two things:
- id: Populated Folder
- use Default Type Information: CMFPlone: Plone Folder
- now you created the type information, click on it to edit it.
- Constructor permission: Add portal content
- Constructor path: portal_types/addPopulatedFolder
#NOTE: the above is 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
to go.
- in portal_properties/site_properties there is a property,
'use_folder_tabs'
in that on a new line add 'Populated Folder' # without the ' - of
course
Why is this? Because Plone attempted to layer functionality onto CMF
instead of
completely replace it. Since we tried to do this there was some
implementation
details (when something is a folder/object) that were exposed. The tab
code is
crufty and old but fairly easy to fix (especially if you arent try to be
all
things to all people).
|