Populator Tool
- Warning
- This product has not had a release in over 1 year and may no longer be maintained.
It is a typical use case to have a container populated with a certain content structure consisting of Folders and other contents. This tool is used to dynamically populate a container type with just such a structure.
Project Description
If you have "News Folder" container, and in that you then want a folder for images and perhaps a folder for other files. It is easier for users if all folders of that type has the same substructure.
This tool can create exactly such a prepopulated structure. The prepoulated structure can even be different for different views.
This tool is special in that it populates the container dynamically upon a view. This has the advantage of being dynamic.
If you decide to change the structure of a content type at a later time, old content types will automatically get the new structure.
It has the disadvantage of possible being slow.
Everytime the "populate" method is called it looks through all the configured content, and checks for changes or missing content. If changes has been made on fixed_attrs they are changed back.
If Content is missing it is added. If everything is ok, nothing is changed. It does not add Zodb bloat.
Using it requires 2 steps
Step 1
Create a configuration script for the content type.
It must return a simple data structure.:
[
{
'id':some_id, # id of the content
'portal_type':some_portaltype, # what portal type must the content be.
'fixed_attrs':[], # Attrs where the value must no be changed
'attrs':{}, # attributes values for the content
'subitems':[], # subcontent. Nested data structure
'config_script':'scriptname', # Configuration script for the content
},
]
The users can actually change the values of 'fixed_attrs', but next time the populate method is called, it will be changed back to the default.
Once the content has been created, the ids are 'locked' so that the populated content cannot be deleted by the user.
It currently only work on archetype based content types.
Here is an example 'PopulatorTool_NewsFolder.py' with nested content:
return [
{
'id':'files',
'portal_type':'Folder',
'fixed_attrs':['title'],
'attrs':{'title':'Files'},
'subitems':[
{
'id':'these-are-files',
'portal_type':'Document',
'fixed_attrs':['title'],
'attrs':{'title':'These Are Files'}
},
]
},
{
'id':'images',
'portal_type':'Folder',
'fixed_attrs':['title'],
'attrs':{'title':'Images'},
'config_script':'PopulatorTool_ImageFolderScript',
},
{
'id':'pdf-files',
'portal_type':'Folder',
'fixed_attrs':['title'],
'attrs':{'title':'PDF files'}
},
]
A script called 'PopulatorTool_ImageFolderScript.py' is used to further configure the 'images' folder. The config script is called like 'obj.PopulatorTool_ImageFolderScript()'. It could look like this:
desc = 'This folder contains images.'
if context.Description() != desc:
context.setDescription(desc)
default_view = 'atct_album_view'
if context.defaultView() != default_view:
context.setLayout(default_view)
Step 2
Call the tool from a page template. Then the content will be populated when the view is called:
<tal:block tal:define="dummy python: here.populator_tool.populate(here, 'PopulatorTool_NewsFolder');" />
To avoid calling the method for every page view you can check the member roles:
<tal:block tal:condition="python:member.has_role(['Owner', 'Manager'], here)"
tal:define="dummy python: here.populator_tool.populate(here, 'PopulatorTool_NewsFolder');" />
It is also possible to put the code into a portlet.
Theres is another trick that can be used here. You can add the populate call under an "action" as a python "condition" on the content type.
Then it will be called everytime the content type us viewed. The trick is to use the fact that the "populate" method returns None, so the action will never be visible. Here is an example of a "dummy" action that calls the populator.:
Title: "Populate"
Id: "populate"
URL (Expression): "string:${object_url}"
Condition (Expression): "python: here.populator_tool.populate(here, 'PopulatorTool_NewsFolder')"
Permission: "Modify portal content"
Category: "object"
Visible?: "checked"
This is a dirty trick and a hack. So please feel bad if you use it. I do.
Installation
Put it in the Products dir and add the tool via the dropdown menu in the old style zope management interface.
License
GPL
Contact
Current Release
Populator Tool 1.0
Released Sep 09, 2006 — tested with Plone 2.5, Plone 2.1
First public release.
More about this release…
-
Get
Populator Tool
for
all platforms
- Product Package / tool
- If you are using Plone 3.2 or higher, you probably want to install this product with buildout. See our tutorial on installing add-on products with buildout for more information.
All Releases
| Version | Released | Description | Compatibility | Licenses | Status |
|---|---|---|---|---|---|
| 1.0 | Sep 09, 2006 | First public release. More about this release… |
Plone 2.5
Plone 2.1
|
GPL | final |

