Home arrow Zope arrow Page 3 - Creating Zope Products

Inner Mechanisms - Zope

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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Now that we've described our Product by building a class, we'll have to work on a few inner mechanisms required to actually use our Product. The first two mechanisms we add to our Product will be responsible for creating instances of that Product. The first one will accept information about the instance to be created, such as the id, title and nickname attributes we make define in __init__. This data will then be passed to the second mechanism. This second mechanism will be responsible for actually adding the instance to Zope based on the data we entered into the first mechanism.

All that's needed for the first mechanism is a simple form that requests the data we use in __init__. Note that this is not included in our Product class, but it does go into the same file.

...

def addForm(self):
   "Accept basic information about the instance."
   out = '<html><head><title>Person Product</title></head><body>'
   out = out + '<form action="addProduct">'
   out = out + '<b>ID:</b> <input type="text" name="id" /><br />'
   out = out + '<b>Name:</b> <input type="text"
name="title" /><br />'
   out = out + '<b>Nickname:</b> <input type="text"
name="nickname" /><br />'
   out = out + '<input type="submit"></form></body></html>'
   return out

As I said above, the addForm method is simply a form that accepts the information we will use to create our instance, id, title and nickname. Once we have this information, we can then use the information to actually create an instance of our Product. To do this, we use the _setObject method:

def addProduct(self, id, title, nickname):
   "Add an instance."
   self._setObject(id, Person(id, title, nickname))
   return "Object created."

We pass the _setObject method two arguments. The first is the id of our instance, and the second is an actual instance of our Person class, to which we pass the information obtained in addForm. Finally, we return a message stating that our object has been created.



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

ZOPE ARTICLES

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