Home arrow Zope arrow Creating Zope Products

Creating Zope Products

The arrangement of Zope objects required for a large website can get somewhat messy and end up looking disorganized. Fortunately, you can use the plethora of Zope Products available to give you a hand, or you can create your own, if there are none that perfectly suit your needs. This article shows you how easy it is to create a Zope Product.

  1. Creating Zope Products
  2. The Stuffing
  3. Inner Mechanisms
  4. Finishing Touches
By: Peyton McCullough
Rating: starstarstarstarstar / 15
March 07, 2006

print this article




A fully functional website powered by Zope can be created by sticking DTML, Zope Page Templates, Scripts and other sorts of objects together. However, this arrangement of objects can quickly turn into a mess if you attempt to create special features or a large website. Things become difficult to create, and the result can look unorganized.

Thankfully, there exists an amazing array of Zope Products. These Products can do a number of things, from allowing the creation of a simple blog to allowing the creation of a full-blown content management system. However, what if you can't find a product that specifically suits your project's needs? If this is the case, then nothing is stopping you from creating your own Zope Products with a bit of Python, which we'll take a look at in this article.

A Class Foundation

Zope Products are simply classes that Zope makes available for usage. Using these special classes, we are free to create multiple instances, with each instance possessing its own unique attributes. For example, look at Script. We can create several Script objects, each with its own name, title, code and any number of custom attributes we choose to define.

Knowing this, it's not hard to figure out that the base of our Zope Product will be a Python class. In this article, we'll take a look at a simple (and useless except for learning purposes) Product named Person. At the core of this Product will, of course, be a Python class named Person. Besides an id attribute and a title attribute (which we'll use to store our virtual person's name), our Person Product will also contain a nickname. Each instance of our Product will have these attributes set to unique values, and the values will be accessible to the outside world in the form of pages.

Go ahead and create a file named person.py. This will store our Python class as well as a few more mechanisms required in our Product (which we'll take a look at later). Create a folder named Person in the lib/python/Products directory of your Zope installation to house our product.

class Person:

Of course, while the above script is perfectly valid Python, it's not much use to Zope. Besides, it doesn't do anything. Before we can call it a Zope Product, we need to do a number of things. We'll start with adding a documentation string to our class. Every class and function you attach to your Zope Product is required to feature a documentation string that explains what that particular class or function does. This forces code to be a bit more readable and organized.

class Person:

   "A virtual person."


We'll also need our class to inherit some basic functionality associated with items. This functionality deals with acquisition and other things. However, this can remain behind-the-scenes for our purposes. It isn't especially important to know everything about what we inherit if we're only developing a simple Product like this one.

import OFS.SimpleItem

class Person(OFS.SimpleItem.SimpleItem):

   "A virtual person."

As you can see, all that's required is that we subclass OFS.SimpleItem.SimpleItem. The next step is to define a variable called meta_type. This is simply the name that our Product will appear as (for example, “Script”, “Folder” and “Page Template”). In this case, we'll set it to “Person”:

import OFS.SimpleItem

class Person(OFS.SimpleItem.SimpleItem):

   "A virtual person."

   meta_type = 'Person'

Now that we got that done, we're now ready to begin stuffing our class with functionality. This functionality comes in the form of methods.

>>> 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: