Hungry Minds Zope Bible Apr 2002 ISBN 0764548573 pdf

  “The Zope Bible is an indispensable, hands-on guide to Zope product development.” % — Paul Everitt, Co-founder and Vice President of Products,

  100% O N E H U N D R E D P E R C E N T Zope Corporation

  C O M P R E H E N S I V E A U T H O R I T A T I V E W H A T Y O U N E E D

  O N E H U N D R E D P E R C E N T Unleash the power of the leading Open Source Web Zo Zo application server Master Zope’s innovative Web object development model Build secure, flexible, and pe pe powerful Web sites and Web applications ™ ™ ope ope ible

  Z Z BONUS CD-ROM Zope plus sample

  Zope

  Bible

  Zope Bible

Michael R. Bernstein, Scott Robertson,

and the Codeit Development Team

  Best-Selling Books • Digital Downloads • e-Books • Answer Networks • e-Newsletters • Branded Web Sites • e-Learning

  Zope™ Bible Published by Hungry Minds, Inc.

  909 Third Avenue New York, NY 10022 www.hungryminds.com

Copyright © 2002 Hungry Minds, Inc. All rights reserved. No part of this book, including interior design, cover design, and

icons, may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording, or otherwise)

without the prior written permission of the publisher. Library of Congress Control Number: 2001118285

  ISBN: 0-7645-4857-3 Printed in the United States of America 10 9 8 7 6 5 4 3 2 1

  1B/SQ/QT/QS/IN Distributed in the United States by Hungry Minds, Inc.

Distributed by CDG Books Canada Inc. for Canada; by Transworld Publishers Limited in the United Kingdom; by IDG Norge

Books for Norway; by IDG Sweden Books for Sweden; by IDG Books Australia Publishing Corporation Pty. Ltd. for Australia

and New Zealand; by TransQuest Publishers Pte Ltd. for Singapore, Malaysia, Thailand, Indonesia, and Hong Kong; by Gotop Information Inc. for Taiwan; by ICG Muse, Inc. for Japan; by Intersoft for South Africa; by Eyrolles for France; by International Thomson Publishing for Germany, Austria, and Switzerland; by Distribuidora Cuspide for Argentina; by LR International for Brazil; by Galileo Libros for Chile; by Ediciones ZETA S.C.R. Ltda. for Peru; by WS Computer Publishing

Corporation, Inc., for the Philippines; by Contemporanea de Ediciones for Venezuela; by Express Computer Distributors for

the Caribbean and West Indies; by Micronesia Media Distributor, Inc. for Micronesia; by Chips Computadoras S.A. de C.V.

for Mexico; by Editorial Norma de Panama S.A. for Panama; by American Bookshops for Finland.

For general information on Hungry Minds’ products and services please contact our Customer Care department within the

U.S. at 800-762-2974, outside the U.S. at 317-572-3993 or fax 317-572-4002. For sales inquiries and reseller information, including discounts, premium and bulk quantity sales, and foreign-language translations, please contact our Customer Care department at 800-434-3422, fax 317-572-4002 or write to Hungry Minds, Inc., Attn: Customer Care Department, 10475 Crosspoint Boulevard, Indianapolis, IN 46256. For information on licensing foreign or domestic rights, please contact our Sub-Rights Customer Care department at 212-884-5000.

For information on using Hungry Minds’ products and services in the classroom or for ordering examination copies, please

contact our Educational Sales department at 800-434-2086 or fax 317-572-4005.

For press review copies, author interviews, or other publicity information, please contact our Public Relations department

at 317-572-3168 or fax 317-572-4168. For authorization to photocopy items for corporate, personal, or educational use, please contact Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, or fax 978-750-4470.

LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND AUTHOR HAVE USED THEIR BEST EFFORTS

  

IN PREPARING THIS BOOK. THE PUBLISHER AND AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH

RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS BOOK AND SPECIFICALLY DISCLAIM

ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. THERE ARE NO WARRANTIES WHICH EXTEND BEYOND THE DESCRIPTIONS CONTAINED IN THIS PARAGRAPH. NO WARRANTY

MAY BE CREATED OR EXTENDED BY SALES REPRESENTATIVES OR WRITTEN SALES MATERIALS. THE ACCURACY

AND COMPLETENESS OF THE INFORMATION PROVIDED HEREIN AND THE OPINIONS STATED HEREIN ARE NOT GUARANTEED OR WARRANTED TO PRODUCE ANY PARTICULAR RESULTS, AND THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY INDIVIDUAL. NEITHER THE PUBLISHER NOR AUTHOR SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR ANY OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR OTHER DAMAGES. FULFILLMENT OF EACH COUPON OFFER IS THE SOLE RESPONSIBILITY OF THE OFFEROR.

  

Trademarks: Hungry Minds and the Hungry Minds logo are trademarks or registered trademarks of Hungry Minds, Inc. in

the United States and other countries and may not be used without written permission. Macromedia and Dreamweaver are

trademarks or registered trademarks of Macromedia, Inc. in the United States and/or other countries. Copyright ©

1997–2000. Macromedia, Inc. 600 Townsend Street, San Francisco, CA 94103 USA. All Rights Reserved. Zope is a trademark

or registered trademark of Zope Corporation. All other trademarks are the property of their respective owners. Hungry Minds, Inc., is not associated with any product or vendor mentioned in this book.

  About the Authors

Michael Bernstein is an information architect for Codeit. He has been a member of

  the Zope development community since it was released as Open Source in late 1998, and wrote the first community-contributed “How-To” for Zope in February of 1999. Michael was one of the technical reviewers for The Zope Book published by New Riders in 2001, and created the Zope category in the Open Directory Project (dmoz.org). Currently residing in Las Vegas, he has worked for two start-ups before joining Codeit and has built and managed various Content Management Systems and intranets using Zope. His interests include Science Fiction Fandom, Open Source, and other self-organizing emergent phenomena. His personal Web site is at .

  http://www.michaelbernstein.com

Scott Robertson co-founded Codeit in 1997, a company dedicated to building cus-

  tom applications that help businesses increase productivity and lower expenses. In 1998, he discovered a technology named Bobo that was so compelling that he learned Python and swore off Perl forever. When Principia (an application built on Bobo) was renamed Zope and released as Open Source, he selected it as Codeit’s preferred Web platform. An ardent believer in Open Source, he has contributed sev- eral products to the community and encourages his employees to do the same. When he’s not working he can usually be found creating strategies for achieving world domination, or at the very least devising ones that will annoy his partners.

  The Codeit Development Team has over 15 years of combined Zope experience.

  Besides the primary authors, other Codeit developers and staff contributed mate- rial to this book, including Nick Garcia, Erik Burrows, Forest Zachman, Brent Rogan, and Sam Stimson. The entire Codeit team is dedicated to using Open Source technologies on behalf of our customers, so that at the conclusion of a project they have the skills, code, and documentation on how to change and scale each application we build, enabling them to be as self-reliant as they wish to be. Beyond development, Codeit also offers Zope hosting as one of its services. Credits

Acquisitions Editor Graphics and Production Specialists

  Terri Varveris Sean Decker Joyce Haughey

  Project Editor Gabriele McCann

  Barbra Guerra Heather Pope Betty Schulte

  Technical Editor

  Tom Deprez Quality Control Technicians Laura Albert

  Copy Editors John Greenough

  Katherine Dvorak Andy Hollandbeck Ryan Rader Carl Pierce

  Linda Quigley

  Permissions Editor Charles Spencer

  Carmen Krikorian

  Media Development Specialist Editorial Manager Travis Silvers

  Kyle Looper

  Proofreading and Indexing Project Coordinator TECHBOOKS Production Services

  Ryan Steffen

  Cover Illustration

  Kate Shaw

  

To Ruth, for doing such a good job raising me; to Roxanne, for making my life

complete; and to Talia, for the future.

  — Michael To Kyle Reid, welcome to the party. Glad you could make it.

  — Scott

  Preface

  i! You’re holding the Zope Bible, a book we suspect will change how you look at building Web sites and Web applications. If you’re like most Web develop-

  H

  ers and designers, you’re probably always looking for ways to improve your pro- cess, both for building and for maintaining Web sites. Whether the sites you’re building are consumer-oriented Web applications, content-centric publishing sites, intranets, or even vanity sites, you want to build them faster, maintain them easier, and integrate other people into your workflow with a minimum of hassle and fuss. Zope is a tool that is hard to describe, as in many ways it’s in a category all its own. So, rather than describe what it is, it’s better to describe what Zope can do for you:

  ✦ Zope contains a templating language for creating dynamic pages, making it easier to create and maintain a common look and feel for your site.

  ✦ Zope uses a powerful scripting language (Python) for creating business logic, making it easy to create powerful Web applications.

  ✦ Zope has a built-in Web management interface so you can create and maintain entire sites with nothing more than a standard browser and an Internet connection.

  ✦ Zope has a built-in object database, making it easy to store content, logic, and presentation in a single place.

  ✦ Zope has a built-in security framework, making it easy and safe to delegate maintenance of sections or subsections of the site to other people.

  ✦ Zope sites are also accessible via FTP and WebDAV, making it easier to lever- age the desktop site creation tools you already use.

  ✦ Zope is written in Python, making it easy to extend and enhance with your own customizations.

  ✦ Zope has built-in content management tools such as Version objects and Undo, which make it easier to safely modify and update a site while it’s “live.” In other words, if you build Web sites, Zope is the tool for you. Zope Bible Why We Wrote This Book

  In the two years since Zope was open-sourced, the user and developer communities have grown tremendously. However, while Zope itself has grown and become both more powerful and easier to use, the documentation has not kept pace. The most glaring omission, the lack of a user manual, was remedied last year with the release of The Zope Book by Amos Latteier and Michel Pelletier (New Riders, 2001). This was a very important milestone, as The Zope Book was a complete refer- ence for using Zope to build Web sites and simple applications. However, by focus- ing on thoroughly covering the basics, it left those who wanted to take advantage of Zope’s more advanced features out in the cold.

  At Codeit Computing, we’ve long wanted a book that could serve as a textbook for educating our own employees, not only teaching them the basics, but more advanced topics as well, such as extending Zope with Python products and building advanced user interfaces. We’ve also wanted a book that we could hand to our clients and their IT staff to make it easier for them to assume the maintenance of the projects that we complete.

  When we were approached to write this book, we determined that this would be our opportunity to write the book that we wished we had all along.

  What You Need

  To follow along with the steps in this book you need to know how to use your browser. Don’t laugh! Zope is very browser-centric. Knowing what the “Back” but- ton does, or that right-clicking a link lets you launch the link target in another win- dow is kind of important when you’re actually using your browser to develop a Web site. This book assumes that you already know how to build Web sites “the old fash- ioned way.” A basic familiarity and ability to write HTML, including tables and forms and using a text editor, will be very handy. In fact, we assume that you’re sick and tired of maintaining your sites by hand.

  A familiarity with some other application server or middleware technology is help- ful, but not really required. Examples of these are Macromedia ColdFusion, Microsoft Active Server Pages, Java Servlets, Java Server Pages, or PHP. Regardless of your operating system, you’ll need to have the appropriate privileges to install software on your computer. Zope is very lightweight, and can be installed on most desktops with a minimum of fuss, but many corporate environments don’t give users the ability to install software.

  Preface DTML, Python, and ZPT Code Conventions This book contains many small snippets of code, as well as complete code listings.

  Each listing appears in a .

  monospace font

  If a line of code doesn’t fit on a single line in this book, We use the arrow (Æ) symbol. For example, the following two lines comprise a single line of code: <dtml-in “listEntriesByGroup(_[‘SelectedGroup’])” size=20 Æ start=start sort_expr=”sort_by”>

  What the Icons Mean

  Throughout the book, we’ve used icons in the left margin to call your attention to points that are particularly important.

  Note

  We use Note icons to tell you that something is important — perhaps a concept that may help you master the task at hand or something fundamental for under- standing subsequent material.

  Tip

  Tip icons indicate a more efficient way of doing something, or a technique that may not be obvious.

  On the CD-ROM These icons indicate that an example file is on the companion CD-ROM. Caution

  We use Caution icons when the operation that we are describing can cause prob- lems if you’re not careful.

  New

  We use this icon to indicate that the material discussed is new to the latest Zope

  Feature version. Cross-

  We use the Cross-Reference icon to refer you to other chapters that have more to

  Reference say on a subject.

  Zope Bible How This Book Is Organized

  This book is organized into four parts that are meant to be read in order if you’re a complete newcomer to Zope.

  Part I: Getting Started with Zope In this section Zope is introduced, as are the fundamentals of coding in DTML and Python. If you are already an experienced Zope user, and want to jump to Part II and

  start developing Python Zope Products, we suggest reading Chapter 5, “Object- Oriented Programming and Python,” in this section first, even if you’re already familiar with Python.

  Part II: Building Zope Products In this section, we build upon the material from Part I, and show you how to extend Zope with new object types. At the end of this section, you will have built a power- ful and useful Web application. Part III: Zope Management Zope provides powerful tools for building and maintaining Web sites. In this sec-

  tion, several aspects of Zope are explored in-depth. Chapter 11 covers content management strategies using Zope, Chapter 12 explains data management including integrating external RDBMSs, and Chapter 13 deals with security and user management.

  Part IV: Advanced Zope Concepts In this section, we’ve put the advanced topics that are relatively independent of

  each other and the rest of the book. Chapter 14 describes in detail the various parts and pieces that Zope is built out of and how they fit together; Chapter 15 covers writing scripts for Zope using Python and/or Perl Script Objects; Chapter 16 covers ZClasses for those who wish to develop products entirely within the browser;

  Chapter 17 explains Zope’s Searching and indexing framework, and how to create automatically indexed content objects; Chapter 18 introduces Zope Page Templates, a new presentation scripting technology introduced in Zope 2.5; Chapter 19 covers Debugging; and Chapter 20 addresses creating and running clusters of Zope servers.

  Appendixes

  Appendix A describes the material included on the CD-ROM, and Appendix B cov- ers installing Zope from source code or RPM files.

  Preface Web Site

  We, the authors of the Zope Bible, have set up a Web site specifically for the readers of this book at . The Web site contains additional infor-

  http://www.zopebible.com

  mation, sample code from the book, links to Zope-related Web sites, and other items and information we think you’ll find useful.

  Acknowledgments

  his book represents a great deal of very hard work (if only we had known what we were getting into), and the authors couldn’t have succeeded without the

  T

  following list of extremely pushy people who insisted they get some credit: The other employees at Codeit Computing, who pitched in to help with individual chapters when we realized we needed their expertise, particularly: Erik Burrows, who wrote a phenomenal chapter on RDBMS integration (Chapter 12); Nick Garcia, who has debugged enough of our code that he was able to write a chapter on how to debug yours (Chapter 19); and Forest Zachman, Zope scripting dude number one (Chapter 15).

  The incredible Zope Development Community, including the following folks from the #zope IRC channel who helped answer both newbie and advanced questions: Kapil Thangavelu (hazmat); Ron Bickers (rbickers); George A. Runyan Jr. (runyaga); Andrew Milton (TheJester); Chris McDonough (chrism); Andreas Jung (YET); R. David Murray (rdmurray); Alex Verstraeten (zxc); M. Adam Kendall (DaJoker); and Morten W. Petersen (Morphex). A special thanks goes to Chris Withers for pitching in on the final review at the last minute. Far too many others in the Zope community, on the mailing lists and in the IRC channel, helped with suggestions, code snippets, HowTos, tutorials, and detailed explanations on every aspect of Zope over the years than could be listed here. We couldn’t have learned as much as we did without the rest of you. The community is a big part of what makes Zope a success. Any remaining bugs in the book’s example code are definitely their fault. Many thanks go to the great folks at Hungry Minds: Terri Varveris, our acquisitions editor, for understanding that we have day jobs and whose efforts went above and beyond the call of duty; Barb Guerra, our project editor, whose gentle guidance forced us into submitting our chapters; Tom Deprez, our technical editor, for help- ing to make the book both clearer and more complete; and Katharine Dvorak and Ryan Rader, our copy editors, who fixed punctuation gaffes, rephrased subjunctive sentences, and cut out unnecessary prepositions with reckless abandon.

  And of course, all the great folks at Zope Corporation, for creating an open-source Web application platform that lets us solve our customer’s problems without creat- ing new ones. Zope Bible Michael adds:

  Besides the folks mentioned above, I’d also like to extend my personal thanks to the following people: My co-author Scott Robertson and Codeit CEO Jason Reid deserve my thanks for giving me the opportunity to write this book and accepting my tendency to perfectionism. Roxanne, for encouraging me when I was down, and keeping my eye on the ball when things just seemed too hard, even though she really deserved my attention more. The members of the Southern Nevada Area Fantasy and Fiction Union (snaffu.org), who deserve my thanks for not complaining even though they didn’t really get the club Vice President they voted for (no, guys, I am not taking you all to Disneyland).

  Scott adds:

  Thanks to my partners, Chris Klein and Jason Reid, who told me to not write a book because I didn’t have time and I’d hate the process (they know me too well) and then helped out in every possible way when I ran into trouble because I never listen.

  Contents at a Glance

  Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv

  

Part I: Getting Started with Zope . . . . . . . . . . . . . . . . . . . . . . 1

Chapter 1: Overview of Zope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Chapter 2: Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Chapter 3: Zope Objects and the Management Interface . . . . . . . . . . . . . . 31 Chapter 4: Document Template Markup Language . . . . . . . . . . . . . . . . . . 65 Chapter 5: Object-Oriented Programming and Python . . . . . . . . . . . . . . . 121 Part II: Building Zope Products . . . . . . . . . . . . . . . . . . . . . . 175 Chapter 6: From Packages to Products . . . . . . . . . . . . . . . . . . . . . . . . 177 Chapter 7: Creating an AddressBook Application . . . . . . . . . . . . . . . . . . 197 Chapter 8: Enhancing the AddressBook . . . . . . . . . . . . . . . . . . . . . . . 231 Chapter 9: Zope Product Security . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 Chapter 10: Creating a Multi-User AddressBook . . . . . . . . . . . . . . . . . . . 291 Part III: Zope Management . . . . . . . . . . . . . . . . . . . . . . . . 309 Chapter 11: Content Management Strategies . . . . . . . . . . . . . . . . . . . . 311 Chapter 12: Database Management . . . . . . . . . . . . . . . . . . . . . . . . . . 335 Chapter 13: User Management and Security . . . . . . . . . . . . . . . . . . . . . 367 Part IV: Advanced Zope Concepts . . . . . . . . . . . . . . . . . . . . 387 Chapter 14: Core Zope Components . . . . . . . . . . . . . . . . . . . . . . . . . 389 Chapter 15: Scripting Zope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439 Chapter 16: ZClasses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455 Chapter 17: Searching Content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491 Chapter 18: Zope Page Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . 517 Chapter 19: Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541 Chapter 20: Alternative Methods of Running Zope . . . . . . . . . . . . . . . . . 557 Appendix A: What’s on the CD-ROM . . . . . . . . . . . . . . . . . . . . . . . . . 567 Appendix B: Installing Zope from the Red Hat RPMs or Source Code . . . . . . . 571 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579

  

Contents

Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv

  Part I: Getting Started with Zope

  1 Chapter 1: Overview of Zope . . . . . . . . . . . . . . . . . . . . . . . . . 3

  What Is Zope? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 History of Zope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Features of Zope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

  Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Database adapters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Web-based user interface . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Integration with existing tools . . . . . . . . . . . . . . . . . . . . . . . . 6 Open source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Extendibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Built-in Web server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Plays nice with third-party Web servers . . . . . . . . . . . . . . . . . . 7 Multiple protocol support . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Indexing and searching . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Built-in object database . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Built-in security model . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Clustering and load balancing . . . . . . . . . . . . . . . . . . . . . . . . 7 Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Undo support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

  Zope Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 ZServer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 ZPublisher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Transaction Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 ZODB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 ZEO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 ZRDBM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

  Zope Advantages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Low cost of ownership . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Fast development/deployment time . . . . . . . . . . . . . . . . . . . 11 Reliability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Scalability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Zope Bible

  Chapter 2: Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 What You Need to Run Zope . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Where to Find Zope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Installing Zope Under Windows . . . . . . . . . . . . . . . . . . . . . . . . . 14 Installing Zope Under Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Finding Your Way around Zope’s Directory Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Starting up Zope for the First Time . . . . . . . . . . . . . . . . . . . . . . . 20 Logging in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Shutting down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Copying your Web site to a different machine . . . . . . . . . . . . . . 23 Running Zope with ZServer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Modifying ZServer’s behavior with switches . . . . . . . . . . . . . . . 24 Using the command line switches

  when running Zope as a service . . . . . . . . . . . . . . . . . . . . 28 Expanding Zope with Products . . . . . . . . . . . . . . . . . . . . . . . . . . 29

  Installing new products . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Product troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . 30

  Getting Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

  Chapter 3: Zope Objects and the Management Interface . . . . . . . 31 Object Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 The Zope Management Interface . . . . . . . . . . . . . . . . . . . . . . . . . 32 Using the top frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Exploring folders with the Navigator frame . . . . . . . . . . . . . . . 35 Manipulating objects in the Workspace frame . . . . . . . . . . . . . . 35 Common Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Viewing objects through the Default view . . . . . . . . . . . . . . . . 37 Examining an object and its Properties . . . . . . . . . . . . . . . . . 37 Changing permissions in the Security view . . . . . . . . . . . . . . . 39 Simulating roles with the Proxy view . . . . . . . . . . . . . . . . . . . 40 Viewing ownership information . . . . . . . . . . . . . . . . . . . . . . 40 Fixing mistakes in the Undo view . . . . . . . . . . . . . . . . . . . . . 40 Folder Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Adding folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 The contents View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Viewing a folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 The Find view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 DTML Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Adding a DTML document . . . . . . . . . . . . . . . . . . . . . . . . . 47 Editing a DTML document . . . . . . . . . . . . . . . . . . . . . . . . . 48 Viewing a DTML Document . . . . . . . . . . . . . . . . . . . . . . . . . 49 Reviewing changes with the History view . . . . . . . . . . . . . . . . 49 DTML Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Introducing the standard header . . . . . . . . . . . . . . . . . . . . . . 51 Overriding the standard header . . . . . . . . . . . . . . . . . . . . . . 52

  Contents

  File Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Adding a file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Editing a file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Viewing a file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

  Image Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Adding an image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Editing an image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Viewing an image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

  User Folders and User Objects . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Adding a User Folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Editing a User Folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Adding a user . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Editing a user . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Managing users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

  Control Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Stopping and restarting Zope . . . . . . . . . . . . . . . . . . . . . . . 59 Managing the database . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Managing versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Managing products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Debug information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

Chapter 4: Document Template Markup Language . . . . . . . . . . . 65 DTML Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Where data comes from . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Understanding variables, properties, and methods . . . . . . . . . . . 67 DTML tag syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 The name attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 The expr attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 The dtml-var Tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Entity syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Attributes of the dtml-var tag . . . . . . . . . . . . . . . . . . . . . . . 80 The dtml-if Tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 The basics of conditional insertion . . . . . . . . . . . . . . . . . . . . 87 The dtml-else and dtml-elif tags . . . . . . . . . . . . . . . . . . . . . . 88 The dtml-unless Tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 The dtml-in Tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 The basics of iterative insertion . . . . . . . . . . . . . . . . . . . . . . 90 The dtml-else tag and empty sequences . . . . . . . . . . . . . . . . . 91 Attributes of the dtml-in tag . . . . . . . . . . . . . . . . . . . . . . . . 92 Current item variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Summary statistic variables . . . . . . . . . . . . . . . . . . . . . . . . 97 Grouping variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Batch processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 The dtml-with Tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 The dtml-let Tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103

  Zope Bible

  The dtml-call Tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 The dtml-return Tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 The dtml-comment Tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 The dtml-raise Tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 The dtml-try Tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107

  Checking for errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Handling multiple exceptions . . . . . . . . . . . . . . . . . . . . . . . 108 Optional dtml-else and dtml-finally tags . . . . . . . . . . . . . . . . . 108 Writing your own error messages . . . . . . . . . . . . . . . . . . . . 109

  The dtml-tree Tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 Displaying objects in a tree . . . . . . . . . . . . . . . . . . . . . . . . 111 Attributes of the dtml-tree tag . . . . . . . . . . . . . . . . . . . . . . 111 Current item variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Control variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

  The dtml-sendmail and dtml-mime Tags . . . . . . . . . . . . . . . . . . . . 117 Creating dynamic e-mail messages . . . . . . . . . . . . . . . . . . . . 117 Sending attachments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118

Chapter 5: Object-Oriented Programming and Python . . . . . . . . 121 Using the Interactive Interpreter . . . . . . . . . . . . . . . . . . . . . . . . 122 Running Python Commands from a File . . . . . . . . . . . . . . . . . . . . 124 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 Types and Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Dictionaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 Control Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 Conditional testing with the If statement . . . . . . . . . . . . . . . . 148 Looping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Understanding Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 Namespaces within functions . . . . . . . . . . . . . . . . . . . . . . 160 Creating and manipulating global variables . . . . . . . . . . . . . . 161 Modules and Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Using modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Playing with the module path . . . . . . . . . . . . . . . . . . . . . . . 163 Importing specific names from modules . . . . . . . . . . . . . . . . 163 Creating and using packages . . . . . . . . . . . . . . . . . . . . . . . 164 Examining the contents of a namespace with dir( ) . . . . . . . . . . 166 Understanding .pyc files . . . . . . . . . . . . . . . . . . . . . . . . . . 166 Classes and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 Defining a new class . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 Class scope versus object scope . . . . . . . . . . . . . . . . . . . . . 167 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 Controlling how classes are initialized with __init__ . . . . . . . . . 169 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

  Contents

  Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 Using the try statement . . . . . . . . . . . . . . . . . . . . . . . . . . 171 The except object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 Catching exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 Using else: with try . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 The finally clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 Raising exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173

  Where Do I Go From Here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173

  Part II: Building Zope Products 175 Chapter 6: From Packages to Products . . . . . . . . . . . . . . . . . 177 What’s a Product? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 Creating a Hello World Package . . . . . . . . . . . . . . . . . . . . . . . . . 179 Publishing Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 Changing a Package into a Product . . . . . . . . . . . . . . . . . . . . . . . 181 Instantiating Your Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 Filling out the manage_add methods . . . . . . . . . . . . . . . . . . 184 Subclassing from Zope base classes . . . . . . . . . . . . . . . . . . . 186 Adding DTML Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 Processing Form Submissions and Returning . . . . . . . . . . . . . . . . . 191 Web-enabling the edit method . . . . . . . . . . . . . . . . . . . . . . 191 Dealing with non-Web situations . . . . . . . . . . . . . . . . . . . . . 193 Adding manage_editHelloForm . . . . . . . . . . . . . . . . . . . . . . 193 Defining your own management tabs . . . . . . . . . . . . . . . . . . 194 Chapter 7: Creating an AddressBook Application . . . . . . . . . . . 197 The Addressit Product and the AddressBook Class . . . . . . . . . . . . . 197 Creating the Addressit Product . . . . . . . . . . . . . . . . . . . . . . 198 Creating edit and index_html Methods . . . . . . . . . . . . . . . . . . . . 201 Creating an Entry Module in the Addressit Product . . . . . . . . . . . . . 205 Adding, Listing, and Deleting Entries from the AddressBook . . . . . . . . 215 Adding entries to the AddressBook . . . . . . . . . . . . . . . . . . . 215 Testing the addEntryForm . . . . . . . . . . . . . . . . . . . . . . . . 220 Listing the entries in the AddressBook . . . . . . . . . . . . . . . . . 222 Traversing the AddressBook into the Entries . . . . . . . . . . . . . . . . . 226 You can’t get there from here . . . . . . . . . . . . . . . . . . . . . . . 226 Improving access to the entries . . . . . . . . . . . . . . . . . . . . . 227 Editing an Entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 Zope Bible

Chapter 8: Enhancing the AddressBook . . . . . . . . . . . . . . . . . 231 Adding a Standard Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 Batching the Entries Display . . . . . . . . . . . . . . . . . . . . . . . . . . 233 Scaling to many results . . . . . . . . . . . . . . . . . . . . . . . . . . 234 About orphans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 Navigating among the batches . . . . . . . . . . . . . . . . . . . . . . 235 Grouping Entries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 Adding a GroupList attribute to

  the AddressBook class . . . . . . . . . . . . . . . . . . . . . . . . . 241 Adding a Group attribute to the Entry class . . . . . . . . . . . . . . 241

  Adding and Deleting Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 Retrieving Entries by Group . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 Renaming Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 Sorting Entries by Column . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257

  Dealing with case-sensitivity . . . . . . . . . . . . . . . . . . . . . . . 263

  Chapter 9: Zope Product Security . . . . . . . . . . . . . . . . . . . . . 267 Security and the Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 Security 101 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 The Web is fundamentally insecure . . . . . . . . . . . . . . . . . . . 268 The Zope Security Framework . . . . . . . . . . . . . . . . . . . . . . . . . 268 Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270 Acquisition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 Ownership . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 Local roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 What Zope won’t do for you . . . . . . . . . . . . . . . . . . . . . . . 273 What Zope will do for you . . . . . . . . . . . . . . . . . . . . . . . . . 273 Determining your Security Requirements . . . . . . . . . . . . . . . . . . . 274 The Default policy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274 Listing the methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274 Reusing existing roles . . . . . . . . . . . . . . . . . . . . . . . . . . . 276 Reusing existing Permissions . . . . . . . . . . . . . . . . . . . . . . . 277 Adding Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 Adding Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 Associating Permissions with roles . . . . . . . . . . . . . . . . . . . 281 Chapter 10: Creating a Multi-User AddressBook . . . . . . . . . . . . 291 Creating the Addressit Class . . . . . . . . . . . . . . . . . . . . . . . . . . 292 Adding AddressBooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 Public and Private AddressBooks . . . . . . . . . . . . . . . . . . . . . . . 301 Adding a Public attribute to the AddressBook class . . . . . . . . . . 301 Using the Public attribute . . . . . . . . . . . . . . . . . . . . . . . . . 302 Incorporating the user’s private AddressBooks . . . . . . . . . . . . 303 Finishing Touches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306 Adding help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306 Adding an Icon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307

  Contents