Zope
  Home arrow Zope arrow Page 4 - 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 - Finishing Touches
    ( Page 4 of 4 )

    Though the person.py file is complete, Zope still will not acknowledge our new Zope Product. This is because there is a bit more work left to do. We have to tell Zope exactly where our Zope Product is located and how to go about adding the Product—what methods are required to create the Product and what-not.

    Thankfully, though, this is a pretty simple process. Zope looks around in the Products directory for __init__.py files. These files contain instructions on what Zope should do to add the particular Product with which the file is associated. Go ahead and create a file named __init__.py and place it in the directory with the person.py file.

    import person

    def initialize(context):
      "Instructions for creating an object."
      context.registerClass(person.Person, constructors =
    (person.addForm,person.addProduct))

    If you followed everything closely, then you should now be ready to test out the Product we created. Simply restart Zope and select our new Product from the drop-down list in the Zope Management Interface.

    There is one additional thing I would like to explain. Though generating all the required HTML in the Python of a Product is perfectly possible, it's not completely practical. A better solution might be to create DTML files and then return those to the user instead. We'll modify our person.py file. The first thing you need to do is import Globals:

    import Globals

    ...

    Next, you need to add an attribute to Person and assign it to the DTML page. We'll use the page dtml_page.dtml here:

       ...

       dtml_page = Globals.HTMLFile('dtml_page', globals())

       ...

    Finally, we must create the DTML page. Put it in the same directory as person.py and name it dtml_page.dtml (even though we don't use the extension in Globals.HTMLFile, the extension is required):

    <html>
       <head>
          <title><dtml-var title></title>
       </head>
       <body>
          This is a DTML page for <dtml-var title>.
       </body>
    </html>

    Conclusion

    From here, there are a lot of paths you can take. Try experimenting with Zope Products a bit more and familiarizing yourself with them. Simple ones aren't difficult to create, as this article has illustrated with the Person Product. You can use them to simplify complex logic that can't be organized using traditional methods. I know that many Python scripters feel that creating numerous Zope objects and attempting to force them to interact is a bit cumbersome, but Zope Products can get around this as well.

    Of course, this article only explains a very small fraction of the inner workings of Zope Products. Products are pretty complex creatures that allow much more customization and functionality than a simple article like this can explain. However, I do hope that this article has introduced you to the very basics of Products so that you can decide where to go next.



     
     
    >>> 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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek