1. Trang chủ
  2. » Công Nghệ Thông Tin

The Zope Bible phần 1 ppt

65 159 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 65
Dung lượng 0,97 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Bernstein, Scott Robertson, and the Codeit Development Team “The Zope Bible is an indispensable, hands-on guide to Zope product development.” — Paul Everitt, Co-founder and Vice Presid

Trang 1

BERNSTEIN &

ROBERTSON

If Zope can do it, you can do it too

Power, versatility, and broad community support have made Zope one of the fastest-growing Open Source

platforms around This in-depth guide brings you up to speed fast on Zope’s innovative Web site and

application development model Two veteran Zope developers cover all aspects of Zope in detail, from

installation to advanced topics like debugging, persistence, and automatic indexing support Whether you’re a

Web developer, a Web architect, or a content manager, you’ll learn all you need to know to put Zope to work

Pentium PC, 128 MB RAM See the

About the CD Appendix for details

and complete system requirements

Build secure, flexible, and powerful Web sites and Web applications

Michael R Bernstein, Scott Robertson, and the Codeit Development Team

“The Zope Bible is an indispensable, hands-on guide

to Zope product development.”

— Paul Everitt, Co-founder and Vice President of Products,

Zope Corporation

,!7IA7G4-feifhe!:p;o;t;T;T

Zope and more

on CD-ROM

BONUS CD-ROM Zope plus sample code from the book

• Adobe GoLive tryout version

• Dreamweaver trial version from Macromedia

• Set up and run Zope on Linux or Windows

• Learn Zope Product development using

Python Products and ZClasses

• Develop a complete multi-user application as

a Python Product

• Master content management and version

control strategies

• Manage databases using SQL and DTML tags

• Use Zope’s built-in security to safeguard Web

sites and applications

• Find out how to run Zope behind Apache using

PCGI, FCGI, or Proxy Pass

You can install the Zope Packages

on Linux using GnoRPM’s point and click interface.

Most of the true work

in Zope is done via the management interface.

Trang 2

Zope

Bible

Trang 4

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

New York, NY ✦ Cleveland, OH ✦ Indianapolis, IN

Trang 5

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.

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.

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.

is a trademark of Hungry Minds, Inc.

Trang 6

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 beforejoining Codeit and has built and managed various Content Management Systemsand intranets using Zope His interests include Science Fiction Fandom, OpenSource, and other self-organizing emergent phenomena His personal Web site is at

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 helearned Python and swore off Perl forever When Principia (an application built onBobo) was renamed Zope and released as Open Source, he selected it as Codeit’spreferred 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 achievingworld 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 rial to this book, including Nick Garcia, Erik Burrows, Forest Zachman, Brent Rogan,and Sam Stimson

mate-The entire Codeit team is dedicated to using Open Source technologies on behalf ofour customers, so that at the conclusion of a project they have the skills, code, anddocumentation on how to change and scale each application we build, enablingthem to be as self-reliant as they wish to be Beyond development, Codeit alsooffers Zope hosting as one of its services

Trang 7

Quality Control Technicians

Laura AlbertJohn GreenoughAndy HollandbeckCarl PierceLinda QuigleyCharles Spencer

Media Development Specialist

Travis Silvers

Proofreading and Indexing

TECHBOOKS Production Services

Cover Illustration

Kate Shaw

Trang 8

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

Trang 10

Hi! 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 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’rebuilding 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

develop-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 iteasier 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 maintainentire 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, andpresentation in a single place

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

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

lever-✦ Zope is written in Python, making it easy to extend and enhance with yourown customizations

✦ Zope has built-in content management tools such as Version objects andUndo, 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

Trang 11

x Zope Bible

Why We Wrote This Book

In the two years since Zope was open-sourced, the user and developer communitieshave grown tremendously However, while Zope itself has grown and become bothmore 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 ing on thoroughly covering the basics, it left those who wanted to take advantage ofZope’s more advanced features out in the cold

focus-At Codeit Computing, we’ve long wanted a book that could serve as a textbook foreducating our own employees, not only teaching them the basics, but moreadvanced topics as well, such as extending Zope with Python products and buildingadvanced user interfaces We’ve also wanted a book that we could hand to ourclients and their IT staff to make it easier for them to assume the maintenance ofthe projects that we complete

When we were approached to write this book, we determined that this would beour 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 yourbrowser 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 Website

This book assumes that you already know how to build Web sites “the old ioned way.” A basic familiarity and ability to write HTML, including tables andforms and using a text editor, will be very handy In fact, we assume that you’re sickand tired of maintaining your sites by hand

fash-A familiarity with some other application server or middleware technology is ful, but not really required Examples of these are Macromedia ColdFusion,

help-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’tgive users the ability to install software

Trang 12

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

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

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

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

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

prob-We use this icon to indicate that the material discussed is new to the latest Zopeversion

We use the Cross-Reference icon to refer you to other chapters that have more tosay on a subject

Trang 13

xii 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 acomplete newcomer to Zope

Part I: Getting Started with Zope

In this section Zope is introduced, as are the fundamentals of coding in DTML andPython If you are already an experienced Zope user, and want to jump to Part II andstart developing Python Zope Products, we suggest reading Chapter 5, “Object-Oriented Programming and Python,” in this section first, even if you’re alreadyfamiliar with Python

Part II: Building Zope Products

In this section, we build upon the material from Part I, and show you how to extendZope 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 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

sec-Part IV: Advanced Zope Concepts

In this section, we’ve put the advanced topics that are relatively independent ofeach other and the rest of the book Chapter 14 describes in detail the various partsand pieces that Zope is built out of and how they fit together; Chapter 15 coverswriting scripts for Zope using Python and/or Perl Script Objects; Chapter 16 coversZClasses for those who wish to develop products entirely within the browser;Chapter 17 explains Zope’s Searching and indexing framework, and how to createautomatically 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 ofZope servers

Appendixes

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

Trang 14

Preface

Web Site

We, the authors of the Zope Bible, have set up a Web site specifically for the readers

of this book at http://www.zopebible.com The Web site contains additional mation, sample code from the book, links to Zope-related Web sites, and otheritems and information we think you’ll find useful

Trang 16

This 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 thefollowing list of extremely pushy people who insisted they get some credit:

The other employees at Codeit Computing, who pitched in to help with individualchapters 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 fromthe #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 forpitching in on the final review at the last minute Far too many others in the Zopecommunity, on the mailing lists and in the IRC channel, helped with suggestions,code snippets, HowTos, tutorials, and detailed explanations on every aspect ofZope 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 asuccess

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 acquisitionseditor, for understanding that we have day jobs and whose efforts went above andbeyond the call of duty; Barb Guerra, our project editor, whose gentle guidanceforced 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 andRyan Rader, our copy editors, who fixed punctuation gaffes, rephrased subjunctivesentences, and cut out unnecessary prepositions with reckless abandon

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

Trang 17

xvi Zope Bible

Roxanne, for encouraging me when I was down, and keeping my eye on the ballwhen things just seemed too hard, even though she really deserved my attentionmore

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 bookbecause I didn’t have time and I’d hate the process (they know me too well) andthen helped out in every possible way when I ran into trouble because I never listen

Trang 18

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

End-User License Agreement 616

Trang 20

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

Trang 21

xx 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

Trang 22

Contents

File Objects 52Adding a file 52Editing a file 52Viewing a file 54Image Objects 54Adding an image 54Editing an image 54Viewing an image 55User Folders and User Objects 55Adding a User Folder 56Editing a User Folder 56Adding a user 56Editing a user 57Managing users 57Control Panel 58Stopping and restarting Zope 59Managing the database 60Managing versions 62Managing products 62Debug information 64

Chapter 4: Document Template Markup Language 65

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

Trang 23

xxii Zope Bible

The dtml-call Tag 104The dtml-return Tag 104The dtml-comment Tag 105The dtml-raise Tag 106The dtml-try Tag 107Checking for errors 107Handling multiple exceptions 108Optional dtml-else and dtml-finally tags 108Writing your own error messages 109The dtml-tree Tag 110Displaying objects in a tree 111Attributes of the dtml-tree tag 111Current item variables 115Control variables 116The dtml-sendmail and dtml-mime Tags 117Creating dynamic e-mail messages 117Sending attachments 118

Chapter 5: Object-Oriented Programming and Python 121

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

Trang 24

Contents

Exception Handling 170Using the try statement 171The except object 171Catching exceptions 172Using else: with try 172The finally clause 172Raising exceptions 173Where Do I Go From Here? 173

Part II: Building Zope Products 175

Chapter 6: From Packages to Products 177

What’s a Product? 178Creating a Hello World Package 179Publishing Objects 180Changing a Package into a Product 181Instantiating Your Object 184Filling out the manage_add methods 184Subclassing from Zope base classes 186Adding DTML Methods 188Processing Form Submissions and Returning 191Web-enabling the edit method 191Dealing with non-Web situations 193Adding manage_editHelloForm 193Defining your own management tabs 194

Chapter 7: Creating an AddressBook Application 197

The Addressit Product and the AddressBook Class 197Creating the Addressit Product 198Creating edit and index_html Methods 201Creating an Entry Module in the Addressit Product 205Adding, Listing, and Deleting Entries from the AddressBook 215Adding entries to the AddressBook 215Testing the addEntryForm 220Listing the entries in the AddressBook 222Traversing the AddressBook into the Entries 226You can’t get there from here 226Improving access to the entries 227Editing an Entry 227

Trang 25

xxiv Zope Bible

Chapter 8: Enhancing the AddressBook 231

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

the AddressBook class 241Adding a Group attribute to the Entry class 241Adding and Deleting Groups 244Retrieving Entries by Group 250Renaming Groups 254Sorting Entries by Column 257Dealing with case-sensitivity 263

Chapter 9: Zope Product Security 267

Security and the Web 267Security 101 267The Web is fundamentally insecure 268The Zope Security Framework 268Roles 270Acquisition 271Ownership 271Local roles 272What Zope won’t do for you 273What Zope will do for you 273Determining your Security Requirements 274The Default policy 274Listing the methods 274Reusing existing roles 276Reusing existing Permissions 277Adding Security 278Adding Permissions 280Associating Permissions with roles 281

Chapter 10: Creating a Multi-User AddressBook 291

Creating the Addressit Class 292Adding AddressBooks 297Public and Private AddressBooks 301Adding a Public attribute to the AddressBook class 301Using the Public attribute 302Incorporating the user’s private AddressBooks 303Finishing Touches 306Adding help 306Adding an Icon 307

Trang 26

Contents

Part III: Zope Management 309

Chapter 11: Content Management Strategies 311

Content Management Concepts 311Content management basics 312Consistency 313Separation of content from presentation 313Separation of Presentation from Logic 315Minimizing redundancy 316Using Acquisition to Enforce Consistency 317

So, what is acquisition? 317Using acquisition to standardize layout 318Navigation 320Using Acquisition to share Logic 323Collaboration and Versions 325What is a version? 325Creating a version 325Joining and leaving a version 326Working in a version 327Saving or discarding your changes 328Things to consider when working with versions 329Applied Security 329Delegation 329Damage Control 331

Chapter 12: Database Management 335

About Relational Databases 335Database basics 335Relational database structure 336Accessing relational databases: SQL 340Real world: Specific RDBMS products 343Connecting Zope to a Relational Database 344Getting an adaptor 344Connecting and disconnecting 345Testing SQL statements 346Browsing tables 347SQL Methods: The Basics 347Static SQL methods 347Dynamic SQL methods 348Using SQL Methods from DTML 349Using the dtml-call tag 351Using the dtml-in tag 351Using SQL Methods from External Methods 352Using SQL Methods from Python Products 353Importing the SQL method class 353Instantiating new SQL method objects 353Calling SQL methods 354

Trang 27

xxvi Zope Bible

Advanced Techniques 354Acquiring parameters 354Traversing to SQL method results 355Pluggable Brains 356Caching 356Transactions 358Building a SQL Application 359Setup a workspace 360Create a new Gadfly connection 360Create the table schema 361Create the SQL methods to access the database 362Write the DTML for the user interface 363

Chapter 13: User Management and Security 367

The Zope Security Framework 367Creating and Managing Users 368Adding a user 368Editing a User 368Setting the allowed domains 370The Emergency User 370Creating the emergency user by hand 370Creating the emergency user with zpasswd.py 371Understanding Roles 372The Anonymous role 372The Authenticated role 372The Manager role 372The Owner role 373Creating roles 373Setting Permissions for Roles 374Proxy Roles 376Giving a proxy role to a method 376Testing the proxy role 378Local Roles 379Using multiple user folders 382Removing a Local role 382Local roles gotchas 383Authentication Adapters 383Installing a custom acl_user folder in the Root Folder 383MySQL User Folder 383SSL Certificate Authenticator 383Cookie User Folder 384

NT User Folder 384SMB User Folder 384etc User Folder 384Generic User Folder 384Login Manager 385UserDB 385LDAPLoginAdapter 385LDAPUserManager 385

Trang 28

Contents

Part IV: Advanced Zope Concepts 387

Chapter 14: Core Zope Components 389

Acquisition 389Understanding wrappers 390Manipulating wrappers 391Context versus containment 396ZODB and Persistence 397Using the ZODB in other applications 398Storing objects and subobjects 399Notifying the ZODB when an object has changed 400Meet the rules of persistence 401Creating attributes that won’t be saved in the ZODB 402Aborting transactions 402Caching and memory management 403Thread safety 408Undoing transaction 410Removing old transactions to save space 410Working with, saving, and aborting versions 411ZPublisher 411Traversing objects 412Publishing the object 413Create Dynamic Text with DocumentTemplates 425Initializing templates with default arguments 427Calling templates 427Working with templates stored in files 428Document template security 428Creating your own tags 430

Chapter 15: Scripting Zope 439

Jumping in with Python Scripts 440Creating a Python-based script 440Script security 443Binding variables 444Under the Hood of a Python Script 445Calling Python-Based Scripts 445Calling scripts from DTML 446Calling scripts from a URL 447

A practical example 448External Methods 449Why external methods? 450

A practical example 450Perl-Based Scripts 452Before installing Script (Perl) 452Installing Zoperl 453Using Perl-based scripts 453

Trang 29

xxviii Zope Bible

Chapter 16: ZClasses 455

What are ZClasses? OOP and Classes 455Through-the-Web ZClasses 456ZClass disadvantages 456Creating a Simple ZClass 456Creating the product 457Creating the ZClass 459Adding a default view 461ZClasses and PropertySheets 464Using simple property types 465Using select and multiple-select properties 471Automatically Generating ZClass Views 473Generating a View interface 473Generating an Edit interface 475Creating Simple Applications Using ZClasses 478FAQManager ZClass 478QandA ZClass 479Finishing the FAQManager interface 483Creating CatalogAware ZClasses 484Making a ZClass catalog aware 485Editing the constructor 485Cataloging changes to the object 487Subclassing ZClasses from Python Base Classes 487Why Subclass Python classes? 488Creating the Python base class 488Subclassing the ZClass from the base class 488Distributing ZClass Products 489

Chapter 17: Searching Content 491

Adding and Populating ZCatalogs 491What is a ZCatalog? 491Adding a ZCatalog to your site 492Populating a ZCatalog 493Configuring and Querying the ZCatalog 494ZCatalog indexes 494ZCatalog Metadata 497Building search interfaces 498Accessing ZCatalogs from Python 505Accessing ZCatalogs from Python script objects 505Accessing ZCatalogs from Python products 507Complex queries from Python 507Making Zope Product Classes auto catalogable

(CatalogAwareness) 508More about ZCatalog 510More about text indexes 510More about field indexes 510

Trang 30

Contents

More about keyword indexes 512More about path indexes 514The Advanced tab 514

Chapter 18: Zope Page Templates 517

The Problem with DTML 517DTML tags are not friendly to HTML editors 518DTML Methods and Documents are not renderable

by WYSIWYG editors 518DTML encourages the mixing of presentation

and logic 519TAL (Template Attribute Language) 520Page template basics 520TAL statements 524Order of TAL statement execution 531TALES (TAL Expression Syntax) 531Path expressions 532Python expressions 534String expressions 535The not: expression flag 536METAL (Macro Expansion TAL) 536Simple code reuse 537Macro slots 538

Chapter 19: Debugging 541

Error Messages 543Debug Mode 545Calling Zope from Python 545The Python debugger (pdb) 547Post-mortem debugging 550Triggering the Python Debugger via the Web 550Logging 552zLOG module 552Profile logging 553Control panel 553Debug information 554Profiling 555

Chapter 20: Alternative Methods of Running Zope 557

Interfacing Zope with Other Web Servers 557Zope and Apache 558Zope and Microsoft IIS 559Zope and Scalability 560What is scalability? 560Clustering and load balancing 561Zope Enterprise Objects 563

Trang 32

Chapter 4

Document TemplateMarkup Language

Chapter 5

Object-OrientedProgramming andPython

I

Ngày đăng: 14/08/2014, 01:20

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN