Zope
  Home arrow Zope arrow Creating Zope Products
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
ZOPE

Creating Zope Products
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 14
    2006-03-07


    Table of Contents:
  • Creating Zope Products
  • The Stuffing
  • Inner Mechanisms
  • Finishing Touches

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Creating Zope Products
    ( Page 1 of 4 )

    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.

    Introduction

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

    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."

       pass

    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
     

       

    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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek