Zope's CMF

Reuven M. Lerner

Issue #111, July 2003

Make your web site's workflow system operate the way your content providers and users want it to work. Develop with the Python-based content management framework.

Over the last few months, we have looked at content management in general and at the open-source Plone content management system (CMS) in particular. Plone certainly is a capable CMS, one that people can use almost immediately upon installation. The main advantage of Plone is its simplicity—it's easy to install, easy to use and easy to customize.

But customizing Plone, or any CMS, can go only so far. If you dislike Plone's boxy look, you undoubtedly can change it in favor of a different model. But if you want a completely different workflow than the one Plone provides, it probably is a waste of time and effort to try to make that sort of change. Rather, it makes sense to write your own CMS or customize one that is designed to be flexible (if more complex) in this area.

Indeed, most CMS vendors recognize that their products need to be customizable if they are going to be useful. If you buy a J2EE-based CMS—and a large percentage of commercial CMS offerings are based on J2EE—you can expect to be able to write new Java objects that describe your content and the way it is published. At a certain point, the division between customizing a CMS and writing your own CMS on an existing infrastructure becomes somewhat blurry.

Enter Zope's content management framework (CMF), designed to provide enough infrastructure for you to create your own CMS. Because Zope development is fairly quick and easy, and because you can use the existing infrastructure that Zope provides, it should be possible to create a CMS at least as quickly (and far more cheaply) than would be possible using a commercial CMS implementation. Plone is implemented on top of CMF, rather than on its own, meaning each time CMF is improved, Plone benefits from those changes.

This month we look at CMF, which is becoming the central focus of the Zope application server. Indeed, although the latest stable version of CMF is 1.3.1, an alpha version of CMF 2.0 is now available. And, if Zope's future directions were any mystery before now, it is clear that CMF 2.0 is “a lightly repackaged head checkout of Zope3”.

Installing and Configuring CMF

We covered how to install CMF several months ago [see At the Forge, LJ, May 2003], so I won't go into detail here. In short, download the latest version from cmf.zope.org and unpack the tarfile into lib/python/Products under your Zope home directory. Then, make symbolic links from the Products directory into the CMF directory for CMFCore, CMFDefault, CMFTopic and CMFCalendar. Restart Zope, and you should see a number of CMF-related products appear in the Add menu within the Zope management screen.

Before we can create any CMF objects, we first need to create a container in which our CMF site can exist. You might notice an obvious parallel here between creating a Plone site and a CMF site. To create a new CMF site, simply choose CMF Site from the Add menu in the web-based Zope management interface. You are asked to name the CMF site, as well as to provide a description.

When you create a CMF site, you also are asked if you want a new user folder within that CMF site or if you want to use an existing user folder. For now, use the existing user folder, meaning that users defined within the top-level Zope site are users within the CMF site. If you prefer to make your CMF site a self-contained unit, without reference (except for the site owner) to the outside world, you may want to create your own user folder.

When you have finished creating your CMF site, you are taken to the home page, which tells you to visit the basic configuration form. Because the CMF originally was known as the Portal Toolkit (PTK), many of the screens refer to portals rather than CMF sites. The information you enter in this form is fairly general in nature, allowing you to set, for example, the e-mail addresses from which generated e-mail appears to come as well as the site's SMTP server.

Things get much more interesting if you follow the directions and go to the CMF management interface, which is really the Zope management interface for the CMF site. In other words, if your CMF site is known as /cmfdemo, you can look at the contents of the site with /cmfdemo/manage. The management screen, as usual in Zope, consists of a small navigation bar on the left. But, as we saw last month, the left side contains a number of portal tools, allowing us to configure and modify our CMF site.

Clicking on portal catalog reveals a vocabulary, Zope's term for an index, that explains how CMF sites are able to provide full-text search without any effort from the site administrator. Clicking on portal types reveals a list of content object classes. These classes form the core of CMF. We look at the content types in greater detail below and will examine how to create our own content types next month.

Finally, click on portal_workflow, which allows you to enter the title of the workflow object you would like to use for each content type. Workflow describes how content moves from writing to publishing, ensuring that only appropriate people are given the authority to perform certain tasks. Authors may write stories, for example, but be unable to publish them to the site. A good workflow system allows you to customize these rules to reflect your organization's needs.

A Simple CMF Site

Now that we have examined the CMF control panel, it's time to examine our site. Upon entering a bare CMF site, we see a main content area in the middle, with several toolbars and boxes in various places. The topmost menu has main navigation links for moving to the top of the site to member pages to the news page and for searching through the site's contents. Underneath that menu, but still in the upper-right corner, is a list of user-specific menus, beginning with My Preferences. This allows logged-in users to set their own preferences, add links to their personal list of favorites and log out. Users who have not logged in to the system are invited to do so if they already have an account or to join the system as a member if they do not yet have an account. On the left is a navigation menu that lists available folders and allows you to set up certain features, such as syndication and local roles.

If you're used to looking at Plone sites, the default CMF site might look a bit spartan but largely familiar. This is because the default CMF site is designed to be used within a custom CMS; even though it is completely functional, it is not designed to be used in real life. By defining new content types and modifying the display skins, you can have a CMS running in almost no time. And because the display logic is separate from the rest of the system, it is possible to change the look and feel relatively quickly.

Every member of a CMF site can be assigned to one or more roles: Member, Reviewer, Manager or Owner. All of these, except Reviewer, should be familiar to experienced Zope users and administrators. The additional role is necessary for handling workflow, in which reviewers must approve content before it is published to the Web.

Administrators are shown an extended menu on the left side of the screen, allowing them to look at a content view of the current folder, which lets them view or modify existing content or create new content within the folder. When you create a new object, you not only assign it an ID (what traditional web systems call a filename) and content, but also metadata that describes the content. Although you cannot change an object's type after it has been instantiated, you can change all of its parameters by returning to the content view and opening the content in question.

Each piece of content must be published before it can be visible to others. By default, new content has a status of private, but it can be published by clicking the publish link on the left menubar. Using the same interface, the site administrator can revoke an article from the site's published list. This is a great improvement over traditional web sites, where we remove links or delete files.

In addition, most content types can have discussions optionally attached to them. This is similar to the Comment on This Posting feature so popular on weblogs, allowing site visitors to add their comments to what the official site administrators have written. As you add a piece of content, you can decide if you want to accept the default site definition for discussions or if you would like to override the site-wide setting specifically for one piece.

Content Types

Exactly what are these content types that we can instantiate? Most of them are defined in the CMFDefault product, in individual .py files within lib/python/Products/CMFDefault. This product defines both the configuration tools we saw earlier in the Zope management interface and also the basic content types, such as NewsItem, Portal, Image and Link, that we can instantiate from within the CMF.

If you're like me, you are surprised and impressed by the small size of most of the default content types defined in the CMF. They range from 100 lines at the low end for NewsItem to under 350 lines for Portal. This not only means it is easy to debug and change these content types if issues come up but that adding a new content type is relatively easy.

Indeed, a number of new content types for CMF have been developed, and it seems to be a growing field. For example, if you visit the CMF Collective Project at collective.sf.net, you can see a number of CMF-related products that have been released in recent months. For example, fledgling CMF products are available for ecommerce, photo albums and weblog creation. As CMF becomes increasingly popular, you can expect to see the CMF Collective similarly grow in popularity.

Conclusion

Because Zope Corp. has said repeatedly that CMF is the future of Zope, and because installing a CMS can be so outrageously expensive, it is clear that Zope Corp. seriously is trying to underbid and outperform its proprietary counterparts. However, because Zope and CMF are open source, we can use them in our own projects both to learn about content management and to edit and publish different items. Next month, we dive in a bit more deeply, looking at how to write your own sample CMF content type.

Reuven M. Lerner (reuven@lerner.co.il) is a consultant specializing in open-source web/database technologies. He and his wife, Shira, recently celebrated the birth of their second daughter, Shikma Bruria. Reuven's book Core Perl was published by Prentice Hall in early 2002, and a second book about open-source web technologies will be published by Apress in 2003.