[Zope] Best Practices for Zope 2 and 3 coding

Troy Farrell troy@entheossoft.com
Sat, 01 Feb 2003 18:13:15 -0600


Pardon the cross-posting.  I'm not sure exactly who would want this most 
helpful information.

Knowing that the majority of my present coding (and all current 
deployments) will be on Zope 2, but that I hope to use Zope 3 when it's 
available, I asked for the best practices on coding a new product for 
both Zope 2 and Zope 3.

You can read my original post here:

http://mail.zope.org/pipermail/zope2-migration/2003-February/000002.html

Here's what Steve Alexander thinks:

-------- Original Message --------
Subject: Re: [Zope2-migration] Best practices for Zope 2 (3?) Component 
Architecture
Date: Sat, 01 Feb 2003 23:50:07 +0200
From: Steve Alexander <steve@cat-box.net>
To: Troy Farrell <troy@entheossoft.com>

Troy Farrell wrote:
 > Thanks Steve.
 >
 > I put it on the z2 migration list because I am referring to coding in
 > Zope2.

Ok, I misunderstood your question. I thought you were asking how to
design such a thing in Zope 3.

The general way to do these things is to write your code so that it
works in Python, then write a Zope 3 wrapper around it (which will be
pretty small), and a Zope 2 wrapper around it (which will be somewhat
larger).

This gets harder when you want to write a product where "web application
framework" features, such as services or acquisition or roles and
permissions, are intrinsic to what you're doing.

Here's an example on how to write a 'collective issues service'.

1: Define your collective issues service interface in python.
     Include a setter interface and a viewing interface.

2: Write python code that implements this API.

3: Write a 'wrapper' around this code that exposes it as a
     Zope 3 product.

4: Write a 'wrapper' around this code that exposes it as a
     persistent SimpleItem in Zope 2. Perhaps use a well-known
     name such as CollectorService.

5: Write an API for a function that you import from some module
     that, when passed a 'context', gets the appropriate 'service'.

6: Implement this function for Zope 3 as a getService call.

7: Implement this function for Zope 2 as a walk up the acquisition
     stack until you acquire a folder that contains your CollectorService
     item.

8: Write an XML or comma-separated-values import/export tool for your
     collector service. Use this to move data between zope2 and zope 3.


For views, use page templates. Write a class derived from
PageTemplateFile that makes 'context' availble instead of 'here' for
Zope 2. (This is only 8 lines of code.)

Security:

    For zope 3, use a configure.zcml file in the package of your zope3
    'wrapper' class.

    For zope 2, use security declarations in your zope2 'wrapper' class.

There are probably other issues too, but this is the general approach
I'd use.