Book Image

Plone 3 Products Development Cookbook

Book Image

Plone 3 Products Development Cookbook

Overview of this book

The Plone Content Management System is one of the best open source CMS, because by using Plone's development framework you can extend its functionality according to the specific requirements of your website. The Plone framework has lots of components that can be used to create add-ons or extensions called Plone Products. You can optimize your site for improved usability, accessibility, and security by creating custom Plone products.This book covers recipes that will help you create custom Plone Products and implement them on your website. Every topic covered in this book is accompanied by essential fundamentals and step-by-step explanation that will help you understand it better. With the help of this book you will be able to create custom Plone products that are well suited for your website.You can read the whole book or just pick recipes relevant for you; cross references help you understand the recipes even if you do not read them in order.If you work through the book in order, you will start by setting up an example project of a news website that will be developed throughout the book. You will learn about all of the necessary tools a Plone developer must have before starting any project. You will develop the website further by detecting problems and debugging them. You will be able to modify code on-the-fly or get help on how to do some tasks by installing and using special tools such as IPython, ipdb, and PDBDebugMode. You will then create a new content type, based on an existing one, and wrap the final product into a Python egg.You will set up automated testing to prevent errors in code that have evolved in the development stage. You will use paster to automatically create a new custom content type from scratch. You will improve the performance of your application by creating lightweight content types and following other recipes covered in this book. Key features such as usability, internationalization, accessibility and security are covered to make sure that your development and customizations will be at the level of Plone core and its most remarkable add-on products.You will improve your user interface by creating simple client-side visual changes and server-side manipulation of objects. You will learn to create and manage portlets by using Portlet manager and customize your website by modifying third-party products. Finally you will learn to communicate with an external non-Python-based system and make your products available for future use.
Table of Contents (21 chapters)
Plone 3 Products Development Cookbook
About the Authors
About the Reviewers

Creating a policy product

A policy product is a regular product that can be installed as other Plone add-ons and will take care of general customizations to meet project needs.

How to do it...

  1. Create a package boilerplate with paster: We have already created several product packages with the paster command. This time it won't be anything special.

    To create the pox.policy product, run the following command inside the src folder of your buildout:

    paster create -t plone

    Provide these values at the options paster prompts:



    Enter project name


    Expert Mode?





    Policy product for PloneOpenX website

    Register Profile


  2. Add the policy product to your instance. In the main [buildout] section, modify the eggs and develop parameters:

    eggs = 
    develop = 

    Optionally, if you want the product to be installed at building time, modify the [plonesite] section:

    recipe = collective.recipe.plonesite
    products = 
  3. Create an extension profiles folder: In the package's folder, create this folder structure:

    mkdir -p ./profiles/default


    In Windows, change the above command to this: mkdir ./profiles/default.

  4. Build your instance up again by running:


How it works...

Policy products are regular products with a special meaning, they configure the website with characteristics the project has and, sometimes, no other project has. Examples of these are the title and description of the site, the initial folders' structure (displayed most of the time on navigation bars), and installation of required products, among others.


The <genericsetup:registerProfile /> directive (found at configure.zcml file) makes Plone aware of this product and turns it installable.

To understand how and when GenericSetup runs special installation scripts, you may find it useful to continue reading until There's more… or have a look at Installing CacheFu with a policy product. The key actions to keep in mind are:

  • Drop extension profiles (special XML files) you need in the profiles/default folder to let GenericSetup automatically install and configure anything you need.

  • If there's no XML-based import step for a specific customization, update configure.zcml with a <genericsetup:importStep /> directive as explained in There's more...

There's more…

In several recipes of this book, we trusted Plone's GenericSetup process to work as we needed: we dropped some special XML files in the profiles/default folder and everything worked as expected.

However, there might be times when we need special steps or actions to be taken when installing a product. For example, we may need to create folders or content inside the portal.

GenericSetup is aware of this requirement many developers have and it supplies a special procedure to get a hook at installation time.

  1. Modify configure.zcml in your pox.policy package:

          title="pox Policy: miscellaneous import steps"
          description=" "
    <!--    <depends name="other step's name"/>  -->

    This will make GenericSetup call the specified handler after all of the dependent import steps (none in our example, that's why we have commented it) had run.

  2. Create a setupVarious method (the above handler) in the file inside the pox.policy package:

    from import getSite
    from Products.CMFCore.utils import getToolByName
    def setupVarious(context):
        if context.readDataFile('pox.policy_various.txt') is None:
        portal = getSite()
        # perform custom operations
  3. Create an empty flag file for the setup handler: In the profiles/default folder, add the pox.policy_various.txt file (read by the setupVarious method) to tell GenericSetup whether to run this step or not.


    When an import step has been run once, it will be run every time GenericSetup is called, even from other products. As the readDataFile method is called in the installing product context, if the flag file is not found, the step handler won't be run. That's why it is important to use unique names for these flag files.

  4. Reinstall the policy product if needed.

See also

  • Changing base class in paster content types

  • Creating a folderish content type

  • Installing CacheFu with a policy product