Question

I'm trying to achieve a repeatable deployment of Plone for a site, and using buildout, basically following Martin Aspeli's book Professional Plone 4 Development. I can set up the system with my source products <site>.policy and <site>.theme, and have activated the theme automatically, but when I run buildout, I still have to instantiate a Plone site and activate the policy product, before creating the standard objects for the site.

Can buildout check for the existence of content objects like the Plone site object or particular folders during setup, and create them if they don't exist with the right settings? Can I do that in a separate <site>.content product, or should this be handled in the <site>.policy?

Was it helpful?

Solution

In principle buildout can do anything you can code, as long as you create a recipe to do the thing for you.

Luckily, someone already created a recipe to create the plone site for you, called collective.recipe.plonesite:

[buildout]
parts = 
    ...
    plonesite

[plonesite]
recipe = collective.recipe.plonesite
site-id = <site>
profiles-initial =
    <site>.policy.profile-default
post-extras =
    ${buildout}/src/<site>.content/site/content/create_content.py

The recipe provides several hooks that let you control site creation, and execute system commands before or after the site is created or extra python code before or after GS profiles are run.

In the above example post-extras runs a create_content.py script with the variables app and site set:

from Products.CMFPlone.utils import _createObjectByType

if 'someobject' not in site:
    _createObjectByType('SomeType', site, 'someobject', title='Foo Bar')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top