Personal tools
You are here: Home Documentation How-tos Creating a Pre-Populated Folder
Support

Get Help

Join our chat rooms or support forums if you have more specific questions.

Plone Training
Learn how to design, build, and deploy a website in Plone through one of the numerous Plone training sessions around the world.
Find Plone training…
 
Document Actions

Creating a Pre-Populated Folder

This How-to applies to: Any version.
This How-to is intended for: Integrators, Customizers

This howto describes one method to create a folder already populated with content.

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.

in ZMI:

  • goto portal_types
  • add new (Script) Python
    • id: addPopulatedFolder
    • title: prepopulated folder
    • parameters: container, id

Code:

    ## 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 to go.

  • in portal_properties/site_properties there is a property, use_folder_tabs. Add Populated Folder to 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).

by Joel Burton last modified May 23, 2007 - 10:35 All content is copyright Plone Foundation and the individual contributors.

setTitle() on the new objects

Posted by stephenhow at March 16, 2005 - 07:39

I found it useful to call setTitle(self,title) and setDescription(self,description) on the newly created object. I've also called these functions in the post_validate() function, after the data fields have been set.

Error:No such content type: Populated Folder

Posted by gaf at March 22, 2005 - 14:48

After trying to test the recipe with green tag link "Neuen Artikel hinzufügen/Populated Folder" this messages follows:

No such content type: Populated Folder

Anny idea what's going wrong here?

AT content types

Posted by John Kavanagh at November 29, 2005 - 23:04

Is setTitle appropriate for Plone 2.1 AT content? When I use it the Title is changed correctly as seen from the content View and Edit actions, but the Folder listing shows the ID and ignores the Title now. Is there a better method for Plone 2.1?

id in navigation

Posted by Tom Hallam at December 6, 2005 - 03:35

I get the same problem: I think it has something to do with updating the catalogue. Not sure how to fix this as yet.

Need to reindex

Posted by Tom Hallam at December 6, 2005 - 04:03

PloneHelpCenter has an example of this for Archetypes. It calls reindexObject() on each newly created sub object.

if faq not in self.objectIds(): self.invokeFactory(HelpCenterFAQFolder,faq) obj = self['faq'] obj.setTitle(self.translate( msgid=phc_faq_title, domain=plonehelpcenter, default=FAQs)) obj.setDescription(self.translate( msgid=phc_faq_description, domain=plonehelpcenter, default=Frequently Asked Questions)) obj.reindexObject()

mmm

Posted by Paul Boots at August 15, 2005 - 22:35

duh, both methods work actually - ? allthough I did get an error first that I couldn't use keyword arguments - ?

Doesn't work with Plone 2.1

Posted by Chris Miles at September 21, 2005 - 13:15

Doesn't work on Plone 2.1 for me. When you try to add a "Populated Folder" you just get a large traceback. I won't paste it here, as this should be reproduceable but it ends with what I've pasted below. Any tips on 2.1-ifying this handy recipe?

  • Module Products.CMFCore.FSPythonScript, line 163, in _exec Module None, line 15, in getSelectableViews Line 15 Module Products.CMFDynamicViewFTI.browserdefault, line 227, in getAvailableLayouts AttributeError: getAvailableViewMethods (Also, an error occurred while attempting to render the standard error message.)

The method cannot work with plone 2.1

Posted by Alec Mitchell at November 1, 2005 - 20:43

The issue is that the UI for Folders in plone 2.1 expects the folders to use the CMFDynamicViewFTI which provides some methods which are unavailable on the Scriptable FTI in use here. The workaround would be to use a folder type which does not implement the BrowserDefaultMixin as the basis for your Scriptable FTI. The other option would be to use one of the many other techniques for doing this like: http://www.mxm.dk/products/public/dmcs/

Will this work in Plone 2.5?

Posted by Tom Schaible at August 22, 2006 - 20:03

I'm trying to get this to work in Plone 2.5. When trying to add a Scriptable Type Information, I only see id and not 'use Default Type Information". If I skip this part, I just end up getting an error about "no view action found" when trying to add the new content type. Does this work with Plone 2.5? Is there an easy way to do something like this in Plone 2.5?

Can do it with initializeArchetype too

Posted by Steve Carson at November 10, 2006 - 04:21
I am using plone2.5 so couldnt get this to work. However if you are using an archetypes based content type you can add
def initializeArchetype(self, **kwargs):
self.invokeFactory(id='folder1', type_name='Folder')
to your content type's class and it will add a folder...

Can do it with initializeArchetype too

Posted by mose mcneil at April 9, 2007 - 18:50
I am using plone 2.5.2 and having the same issue "no view action found" I tried to use Can do it with initializeArchetype too - but I am missing the basics where do I got to do this? do I add the lines in as part of a script or should this be in the drop down menu. Pardon me for my ignorance but any help would be greatly appreciated.

loop through line field values

Posted by Elham Yousif Al-Mulla at May 23, 2007 - 00:12
can we create folder content based on the values specified in one of its line fields?
EX: creating departments inside a directory based on 'Department' lines fields values

For any issues with the web site functionality, please file a ticket.

Please consult the policy on plone.org content if you want your content published on this site.

Servers and hosting by