|
|
||||||||||||||||||
|
|
||||||||||||||||||
![]() |
![]() |
Issue 3 - Revision 5 / April 9, 2003
|
|||
|
Introduction to Zope 3 - Part I of II - - - - - - - - - - - - By Steve Alexander | March 20, 2003 Overview The present article deals with the following topics:
There's been a lot of buzz about Zope 3. We've had sprints and sprintathons where both programmers and user-interface designers have come together for 3 days to a week to move Zope 3 forward: http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/SprintSchedulePictures of the Sprintathon here: http://www.infrae.com/sprintathonWe've had an "alpha" release of Zope 3X, so that a wider audience of Zope software developers can get a feel for how Zope 3 development is going. http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/DownloadsThere's another "alpha" release of Zope 3X due any day now. I'll say a few words about the difference between "Zope 3X" and "Zope 3" a bit further down. We've had over 100 Proposals for improvements and enhancements from the Zope community, many of which have been implemented. http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/Zope3ProposalsWe have over 3000 unit tests, which get run on the code in CVS every night on Windows, Linux and FreeBSD. A unit test is a short program that is used to check that parts of a large program work correctly. Every piece of Zope 3 code is accompanied by a 'unit test' program. But what is Zope 3, and what will it mean to Web developers and applications programmers? I hope the rest of this article will show where Zope is going, and what you'll be able to do when we get there. So what is Zope 3?Zope 3 is fundamentally a lot like Zope 2. It is about publishing objects and content and programs as Web pages, with flexible security, storing data in the ZODB, querying relational databases, scripting languages... Everything you can currently do with Zope 2, you'll be able to do with Zope 3. But also a lot of things that are hard to do or complex in Zope 2 will be at least somewhat easier with Zope 3. I think of Zope 3 as being what you would get if you pulled Zope 2 apart and then put it back together in a better way. But not only that, if you put it back together like so many Lego bricks, so you could easily rearrange it again later, to suit your needs. Further down, I'll explain by way of some concrete examples of how things are different in Zope 3. Above I mentioned "Zope 3X" and "Zope 3". Right now, the Zope 3 development community is working on a project called "Zope 3X". The "X" is really just a marker to distinguish it from "Zope 3", but it might stand for "X the Unknown" or "eXperimental" or "eXtreme". What this means is: we are building Zope 3X without worrying about whether what we do is backwards-compatible with Zope 2. This gives us a lot of freedom to do things better, and to create innovative solutions to problems. But, Zope 3X is not Zope 3. Once development of Zope 3X has slowed down, and we have a stable base to start from, work can start on Zope 3 proper. Zope 3 will take its inspiration from Zope 3X, but will contain extra code to help with backwards-compatibility. In summary:
Some people have expressed the worry that since some of the people who were working on Zope 2 are focusing their time and energy on Zope 3, Zope 2 might be on the way out. Zope 2 isn't dead; far from it. Rob Page, CEO of Zope Corporation issued the following statement: "Zope Corporation will continue to support, enhance, and solicit enhancements for Zope 2.x for the foreseeable future." http://www.zope.com/News/ZopeRoadmapThere's been a lot of discussion about the importance of providing a smooth transition for those who want to move from Zope 2 to Zope 3. Jim Fulton recently said: "It's critical to the many Zope businesses around the world, including ZC, that the transition from Zope 2 to Zope 3 be as clear and understandable as possible." http://mail.zope.org/pipermail/zope2-migration/2003-February/000092.htmlThere will be some means of migrating code and data from Zope 2 to Zope 3, but it is too early to start working on this now. Zope 3 is still under development, and still changing quite a lot. Zope 3 for developers and usersIn this article, I want to give a taste of the shape of things to come. Like forecasting the weather, this can't be done with absolute certainty. Things I say here will probably change before Zope 3X is finished and this will have an effect on the shape of Zope 3. Nonetheless, the kind of facilities I describe will be available in some form. Some of this article describes things that exist already and that you receive when you download Zope 3X from CVS, or they will be in the next alpha release. Other things are planned for inclusion later, depending upon when people will have the time to write them. What has stayed the same between Zope 2 and Zope 3Zope 3 is still about taking objects and publishing them in various ways through the Web, and via FTP and XML-RPC. There is still integrated security based on users, roles and permissions. But...:
There are still scripts and templates and pages and queries that you can add using a browser.
(I'll talk about Adapters further down.) Zope is still written in Python
Rather than explain how Resources, Views and Services work, I'll give a few examples of when you'd use them. Resources
In Zope 2, you might put all of your images and CSS style sheets and .js JavaScript files into a folder inside the root folder, called 'Images'. You would then use acquisition to acquire 'Images/picture.jpg' from other pages in your site. You can use Resources for this in Zope 3. Each of your images and style sheets and other files becomes a Resource. You can access them from a page template like this: <img tal:attributes=”src context/@@/picture.jpg/absolute_url” /> The Resources Service ensures that a resource appears to come from the same absolute URL no matter where you access it from. This is important for allowing images and other large files to be cached in HTTP proxy caches. Views
Let's say you have a number of text files in different folders. In Zope 2, you can add a script in your root folder called 'summary_html' that extracts the first paragraph of text from a file and presents it to the browser. So, if you have the GNU Public Licence as a text file called 'gpl', if you go to http://example.com/licences/gpl/summary_html, you will see the summary of the GPL. In Zope 3, you achieve the same thing by adding your script as a "view" that should apply to all text files. The advantage is that there is no need to have something called "summary_html" in your root folder. Also, this view is only used for text files, not for other kinds of things. So, there is no danger of inadvertantly using "summary_html" for an image or a folder. Zope contributor Toby Dickenson humourously points out the dangers of this kind of thing in this message to the Zope developers' mailing list. http://mail.zope.org/pipermail/zope-dev/2000-October/007495.html Services
When you want to send email from a page in Zope 2, you add a MailHost in the root of your site, and use the <dtml-sendmail> tag or a Python script to format the email and send it off. In Zope 3, you add an SMTP Mail Service, and use the <dtml-sendmail> tag or a Python script to format the email and send it off. The difference is that, in Zope 3, there is no object called 'MailHost' in your root folder. Nothing will go wrong if someone decides to call a file 'MailHost' in some folder.
Look carefully at the screenshot above of a folder with stuff in it. The image 'graphic.png' in that folder tells you its size in KB, and its dimensions in pixels. The folder doesn't know how to do this. Otherwise, we'd have to keep extending the Folder code for each new kind of thing we wanted to add to a folder. On the other hand, since an image doesn't know how to behave as the contents of a folder, it would require that the programmer add code to the image's class to show its size in a list of folder contents. That would put an onerous requirement on people who want to write products for Zope 3. Instead, a simple 'adapter' knows how to show the size of an image. An adapter is an object that knows how to 'translate' one kind of object into another kind so that it can work under circumstances other than those it was originally designed for. In this case, we have an adapter that knows how to present the size of image objects. There are different adapters for images and page templates and folders and files. The file's size is shown in MB, the template tells you how many lines of html and script it has, and the folder tells you how many items it contains: each of these presentations of "size" is achieved by means of a different kind of adapter. Let's take a look at the code that adapts a folder (or other container) to give its size in "items".
class ContainerSized:
implements(ISized)
def __init__(self, container):
self._container = container
def sizeForSorting(self):
"""See ISized"""
return ('item', len(self._container))
def sizeForDisplay(self):
"""See ISized"""
num_items = len(self._container)
if num_items == 1:
return '1 item'
return '%s items' % num_items
That's it. That's an adapter. In the sizeForDisplay() method, it finds out the number of items in the container, and presents it either as "1 item" or as, say, "23 items" depending on the number of items it has determined. The Sized adapter for images is similar, and like the adapter shown above, has a sizeForSorting method and a sizeForDisplay method. You can see what these methods are supposed to do in the ISized interface:
class ISized(Interface):
def sizeForSorting():
"""Returns a tuple (basic_unit, amount)
Used for sorting among different kinds
of sized objects.'amount' need only be
sortable among things that share the
same basic unit."""
def sizeForDisplay():
"""Returns a string giving the size.
"""
An interface looks a bit like a class, but it doesn't actually do anything. It defines what methods and attributes something needs to have to meet expectations. The documentation tells you what these expectations are. There's an Adapters Service whose job it is to keep track of what adapters are available, and what kinds of objects and interface expectations they work for. End of Part I - For the next part of this article covering ZClasses in Zope 3 as well as an example Development scenario click here.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ZopeMag is committed to bringing you the best in Zope Documentation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
Reproduction of material from any of ZopeMag's pages without prior written permission is strictly prohibited. Copyright 2003 - 2005 ZopeMag |
|