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
Credits
About the Authors
About the Reviewers
Preface
Index

Installing Plone on Linux


Now that we have a valid Python version, we can install Plone.

Note

There is an alternate and very handy method to install Plone on Linux (and Mac and Windows) called Unified Installer. It is a bundle that installs not only Zope and Plone, but also Python and other necessary packages. If you want to try it, go to http://plone.org/download and download the version of your choice.

Getting ready

ZopeSkel is a Python package that provides development templates for Zope and Plone. It will help us at several different stages of our projects. We will use it here to create a buildout environment. First, we must be sure we have it properly installed:

  1. Activate your just installed Python 2.4 (or whatever version you have installed) virtualenv:

    $ source ~/libexec/python2.4/bin/activate
    
  2. Install ZopeSkel:

    (python2.4)$ easy_install-2.4 ZopeSkel
    
  3. If you already have it, check for the latest version by running:

    (python2.4)$ easy_install-2.4 -U ZopeSkel
    

How to do it…

  1. Create a buildout with paster: Once you have the correct ZopeSkel version installed for your Python environment, run the following command to create a Zope/Plone buildout:

    (python2.4)$ paster create -t plone3_buildout
    

    Note

    Starting with ZopeSkel 2.15, when creating buildout environments with paster, you will see a warning message informing you that Unified Installer is the best option for installations and paster is just for experts. Although Unified Installer is great and incredibly useful, we think Plone developers should know how to create a Plone environment from scratch and this is the way to do it.

  2. Run the bootstrap process:

    (python2.4) $ cd pox
    (python2.4) $ python bootstrap.py
    
  3. Edit the buildout.cfg file and locate the eggs parameter in the main [buildout] section and add PIL (Python Imaging Library) as a package to be downloaded and installed during buildout.

    [buildout]
    ...
    eggs = 
        PIL
    ....
  4. Buildout your Zope instance: This last step is to run the buildout process.

    (python2.4) $ ./bin/buildout
    

How it works…

Executing Step 1 will start a wizard to help with the creation of the buildout.cfg, we need. For each of the following options, provide these values:

Option

Value

Enter project name

pox, after Plone and OpenX, the fictitious project we are tackling in this book. Here you can choose whatever name you want and paster will create a directory with that name.

Expert Mode?

With the plone3_buildout template, no matter which mode you choose (easy/expert/all), you’ll be prompted for the following options.

Plone Version

A valid released version of Plone. Although we have run paster with the plone3_buildout template, we can enter Plone 4 version numbers. Don’t forget to choose 3.x versions for Python 2.4 and 4.x versions for Python 2.6.

Zope2 Install Path

If you want to share this instance Zope installation with another existing one, enter its path. If not, just leave it blank.

Plone Products Directory

Again, if you already have a previous installation with the list of Plone products you want to use, enter its path. If you want a fresh installation, leave it blank.

Initial Zope Username

The desired Zope administrator user.

Initial User Password

Choose one. Don’t leave it blank, as you won’t be able to log in.

HTTP Port

Pick a free port in your development machine.

Debug Mode

off

Verbose Security

off

A new folder named pox (the project name we used in the first option) with a basic directory structure and two very important files—bootstrap.py and buildout.cfg— will have been created.

In Step 2, we run the bootstrap process to complete the directory structure and generate the executable buildout file.

Let’s see what buildout.cfg looks like after Step 3, where we added PIL in the eggs parameter:

[buildout]
parts =
    zope2
    productdistros
    instance
    zopepy

This is a four-part buildout. Each part will be run consecutively.

extends = http://dist.plone.org/release/3.3.4/versions.cfg
versions = versions

Egg version numbers will be fixed (or pinned) to the ones listed in the URL above. Note that the URL is set according to the release number you have chosen when you ran the paster command before.

find-links =
    http://dist.plone.org/release/3.3.4
    http://dist.plone.org/thirdparty

Downloaded and installed eggs should be fetched from these package index servers.

# Add additional eggs here
eggs =
    PIL

# Reference any eggs you are developing here, one per line
# e.g.: develop = src/my.package
develop =

We will start using the eggs and develop parameters in the next chapter as we begin adding packages to our Zope instance. Meanwhile, we will need Python Imaging Library (PIL).

[zope2]
# For more information on this step and configuration options: 
# http://pypi.python.org/pypi/plone.recipe.zope2install
recipe = plone.recipe.zope2install
fake-zope-eggs = true
url = ${versions:zope2-url}

A recipe for Zope 2 installation:

[productdistros]
recipe = plone.recipe.distros
urls =
nested-packages =
version-suffix-packages =

A special recipe to download and install old-style Zope products (not released as eggs):

[instance]
recipe = plone.recipe.zope2instance
zope2-location = ${zope2:location}
user = admin:admin
http-address = 8080
#debug-mode = on
#verbose-security = on
eggs =
    Plone
    ${buildout:eggs}

# If you want to register ZCML slugs for any packages, 
# list them here.
# e.g. zcml = my.package my.other.package
zcml =

products =
    ${buildout:directory}/products
    ${productdistros:location}

These are several configuration settings for the Zope instance that will be created during the buildout process.

[zopepy]
recipe = zc.recipe.egg
eggs = ${instance:eggs}
interpreter = zopepy
extra-paths = ${zope2:location}/lib/python
scripts = zopepy

zopepy is a Python interpreter with a sys.path variable full of the downloaded eggs and packages available at the instance's /lib/python folder. This is particularly useful to check if every package is available as expected.

The last step will take longer to execute than the previous steps, as it will download all the eggs listed in the buildout.cfg file above and all their dependencies (at the time of writing, Plone 3.3.4 has 74 direct dependencies).

This buildout executes the four parts explicitly mentioned in the parts definition at the top of the file:

  • [zope2]: Its plone.recipe.zope2install recipe downloads and installs the Zope 2 version mentioned in ${versions:zope2-url}. You can find this parameter at http://dist.plone.org/release/3.3.4/versions.cfg, the URL of the extends parameter.

  • [productdistros]: It executes with its plone.recipe.distros recipe. In our example, we don’t have any urls listed, so it won’t process anything here.

    Note

    Note that there are very few old-style Zope products that are really worth installing in a modern instance. Being old-style means being unmaintained, so use them carefully.

  • [instance]: It uses a plone.recipe.zope2instance recipe to install a Zope instance. We can see here most of the options we set when we ran the paster command before.

  • [zopepy]: Using zc.recipe.egg will create a Python interpreter named zopepy with all the eggs found in the instance section (check ${instance:eggs}) in the sys.path variable.

See also

  • Installing Python on Linux

  • Installing and configuring an egg repository

  • Writing a production buildout