Home arrow Zope arrow Page 2 - Plone Content Types With Archetypes

A Quotation Content Type - Zope

Plone is an excellent content management system. You will probably find everything you need in the system itself, or from third party content types. If you don't, however, it is very easy to create your own content types, as this article will explain.

  1. Plone Content Types With Archetypes
  2. A Quotation Content Type
  3. Mutators and Accessors
  4. Validators
By: Peyton McCullough
Rating: starstarstarstarstar / 16
February 28, 2006

print this article



We'll start with the example I described in the previous section, a simple quotation content type. When an object based off the content type is added, text fields for the speaker of the quotation and the quotation will be presented. After they are filled out and the form is submitted, the object will be created. When the object is viewed, it will display the speaker and the quotation.

Create a folder called Quotation in the Products directory. This is where we'll store our content type's files. The first file we will create is config.py. This defines some constants that we'll use throughout our content type:

from Products.CMFCore.CMFCorePermissions import AddPortalContent

GLOBALS = globals()
PROJECTNAME = "Quotation"

In config.py, we first define the permission required to manipulate our content type. Since our content type really isn't anything special, we just assign it to the generic AddPortalContent permission. We then define a constant called GLOBALS, which is used during the installation of our content type. Finally, we give our content type (or project/product, rather, since it's possible to have multiple content types in the same package) a name.

Next, we'll have to create our content type's schema, which will define the fields associated with the content type. When we edit quotations, we'll want a text field for the speaker and a larger text area for the quotation itself. All of this is specified in the schema:

from Products.Archetypes.public import *
from Products.Quotation.config import *

schema = BaseSchema + Schema((
   TextField('speaker', required = True),
   TextField('quotation', required = True, widget = TextAreaWidget)

class Quotation(BaseContent):
   "A simple quotation content type."
   schema = schema

registerType(Quotation, PROJECTNAME)

The first thing we do is create our content type's schema. We create two text fields, one for the speaker and one for the quotation. Both are required to be filled out. The second one is also set to a text area. Next, we create the content type's class, where we simply copy the schema, and, finally, we register the content type.

Next is __init__.py, where we glue what we've done so far together:

from config import *
from Products.Archetypes import process_types, listTypes
from Products.CMFCore import utils

def initialize(context):
   import Quotation
   content_types, constructors, ftis = process_types(listTypes
   utils.ContentInit(PROJECTNAME, content_types = content_types,
                     extra_constructors = constructors, fti =

Besides importing our configuration file and various methods that we'll be using, the first thing we do is define a function and import our Quotation.py file. From there, we get some information about our package, the content types associated with it, constructors and factory type information, in that order. We then create a utils.ContentInit with this information, along with the package name and the permission we defined in config.py.

Finally, we have to create Install.py, which is responsible for installing our product. Create a folder called Extensions inside Quotation to place the install script in:

from Products.Archetypes.Extensions.utils import installTypes
from Products.Archetypes.public import listTypes
from Products.Quotation.config import PROJECTNAME, GLOBALS
import StringIO

def install(self):
   out = StringIO.StringIO()
   installTypes(self, out, listTypes(PROJECTNAME), PROJECTNAME)
   out.write("Installed: " + PROJECTNAME)
   return out.getvalue()

This simply installs our content type and inserts a short message into the installation log.

Our Quotation content type is now complete. Restart Zope and then install the product in the “Add/Remove Products” section of Plone. You should now be able to add an object based off our content type to a folder.

You can also create the files version.txt and README.txt. The contents of the former file will be added to the product's name, and the contents of the latter file will be displayed as the product's description.

>>> More Zope Articles          >>> More By Peyton McCullough

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Creating Zope Products
- Plone Content Types With Archetypes
- Flat User Management in Zope
- Creating Basic Zope Applications
- Getting started with Zope for Linux and Sola...
- ZPT Basics (part 4)
- ZPT Basics (part 3)
- ZPT Basics (part 2)
- ZPT Basics (part 1)
- Exception Handling In DTML
- DTML Basics (part 4)
- DTML Basics (part 3)
- DTML Basics (part 2)
- DTML Basics (part 1)
- Using Zope With Apache

Developer Shed Affiliates


Dev Shed Tutorial Topics: