Sunday, April 24, 2011

Creating new content types using Dexterity for Plone 4 on OS X

update: These steps should work with little adjustment on a Linux base OS also.

This is a short write-up that helps you to quickly jump to the "important" section of the dexterity manual (http://plone.org/products/dexterity/documentation/manual/developer-manual/schema-driven-types/referencemanual-all-pages). Hopefully this will minimize some of the fumbling on OS X (and Linux also). I provide some boiler plate code that should help you to skip some of the initial coding and hopefully save you some trivial errors.

I'm assuming that you already have dexterity configured to work with your Plone 4 instance, if you don't go and read Get Started with Dexterity Development for Plone 4 on OS X. I also assume that you have a working version of git, so ensure that you have a working installation of git.

Back already? Great!

Through the Web (TTW) Content Types (Warm up exercise)
This exercise will help you to appreciate some of the principles associated with dexterity based content types in Plone.
Start your Plone instance
Then go to 'admin''Site Setup' → 'Add-ons', check 'Dexterity content types' and click 'Activate'.


Now go back to "Site Setup", select "Dexterity Content Types" and start tinkering with it.


Then create a new content type called 'Person'. You can do this by clicking 'add new content type' (see the screencast below):











That's it.

Creating a content type with filesystem code
Now that you've seen the through the web (TTW) approach, let's look at storing code on the filesystem. The filesystem based approach is better for version management (e.g. with git) and redistribution of the code.

To make your life easier, I've created some boilerplate code based on the dexterity manual. The instructions below will get you started quickly (assuming you already have Plone and git installed).

Step 1 - Get the example configuration file:
Get the 'example.conference.cfg' from here and place it in the same folder that contains your buildout.cfg.

Step 2 - Update buildout.cfg to use the new configuraiton file:
The changes will look something like this;

extends =
base.cfg
versions.cfg
http://good-py.appspot.com/release/dexterity/1.0-next?plone=4.0.5
example.conference.cfg

eggs =
Plone
PIL==1.1.6
plone.app.dexterity
example.conference

The re-run buildout:

bin/buildout

Step 3 - Customize the example.conference product with new content types

Add 3 new files to src/example.conference/example/conference, presenter.py, program.py, and session.py.

Step 4 - Register the new content types as Factory Types

Once you've done this you should now be able to install the conference management system and add new programs, sessions and presenters, to your Plone site.

No comments:

Sign up for my upcoming Plone 5 Book & Video tutorials

plone 5 for newbies book and videos