The Zope Book (2.6 Edition)
Total Page:16
File Type:pdf, Size:1020Kb
The Zope Book (2.6 Edition) Amos Latteier, Michel Pelletier, Chris McDonough, Peter Sabaini The Zope Book (2.6 Edition) Preface 32 How the Book Is Organized 32 Conventions Used in This Book 34 Contributors to This Book 35 Introducing Zope 36 What Is A Web Application? 36 How You Can Benefit From Using An Application Server 37 Zope History 38 Why Use Zope Instead of Another Application Server 38 Zope Audiences and What Zope Isn't 39 Zope's Terms of Use and License and an Introduction to The Zope Community 40 Zope Concepts and Architecture 41 Fundamental Zope Concepts 41 Zope Is A Framework 41 Object Orientation 41 Object Publishing 41 Through-The-Web Management 42 Security and Safe Delegation 42 Native Object Persistence and Transactions 43 Acquisition 43 Zope Is Extensible 43 Fundamental Zope Components 44 Installing and Starting Zope 45 Downloading Zope 45 Installing Zope 45 Installing Zope for Windows With Binaries from Zope.org 46 Installing Zope on Linux and Solaris With Binaries from Zope.org 50 Compiling and Installing Zope from Source Code 52 Starting Zope 53 Using Zope With An Existing Webserver 54 Starting Zope On Windows 54 Starting Zope on UNIX 54 Starting Zope As The Root User 55 Your Zope Installation 55 Logging In 56 Controlling the Zope Process With the Control Panel 57 2 The Zope Book (2.6 Edition) Controlling the Zope Process From the Command Line 57 Troubleshooting 58 Options To The Zope start or start.bat Script 58 Environment Variables that Effect Zope at Runtime 61 When All Else Fails 65 Object Orientation 66 Objects 66 Attributes 67 Methods 67 Messages 67 Classes and Instances 68 Inheritance 68 Object Lifetimes 69 Summary 69 Using The Zope Management Interface 70 Introduction 70 How The Zope Management Interface Relates to Objects 70 ZMI Frames 70 The Navigator Frame 70 The Workspace Frame 71 The Status Frame 72 Creating Objects 72 Moving and Renaming Objects 73 Transactions and Undoing Mistakes 75 Undo Details and Gotchas 76 Reviewing Change History 76 Importing and Exporting Objects 77 Using Object Properties 80 Using the Help System 82 Browsing and Searching Help 82 Logging Out 83 Using Basic Zope Objects 84 Basic Zope Objects 84 Content Objects: Folders, Files, and Images 84 Folders 84 Files 84 Creating and Editing Files 85 3 The Zope Book (2.6 Edition) Editing File Contents 86 Viewing Files 86 Images 87 Presentation Objects: Zope Page Templates and DTML Objects 87 ZPT vs. DTML: Same Purpose, Different Audiences 88 Zope Page Templates 89 Creating A Page Template 89 Editing A Page Template 89 Uploading A Page Template 89 Viewing A Page Template 90 DTML Objects: DTML Documents and DTML Methods 90 Creating DTML Methods 91 Editing DTML Methods 91 Viewing a DTML Method 92 Uploading an HTML File as Content for a DTML Method 92 Logic Objects: Script (Python) Objects and External Methods 93 Script (Python) Objects 93 Creating A Script (Python) 94 Editing A Script (Python) 94 Testing A Script (Python) 94 Uploading A Script (Python) 95 External Methods 96 Creating and Editing An External Method File 96 Creating an External Method Object 96 Testing An External Method Object 96 SQL Methods: Another Kind of Logic Object 97 Creating a Basic Zope Application Using Page Templates and Scripts 97 Creating a Data Collection Form 98 Creatng A Script To Calculate Interest Rates 98 Creating A Page Template To Display Results 99 Dealing With Errors 99 Using The Application 100 The Zope Tutorial 100 Acquisition 102 Acquisition vs. Inheritance 102 Acquisition is about Containment 103 Say What? 103 4 The Zope Book (2.6 Edition) Providing Services 104 Getting Deeper with Multiple Levels 104 Summary 104 Basic DTML 106 How DTML Relates to Similar Languages and Templating Facilities 106 When To Use DTML 106 When Not To Use DTML 106 The Difference Between DTML Documents and DTML Methods 107 Details 107 DTML Tag Syntax 108 DTML Tag Names, Targets, and Attributes 108 Creating a "Sandbox" for the Examples in This Chapter 109 Examples of Using DTML for Common Tasks 109 Inserting Text into HTML with DTML 109 Formatting and Displaying Sequences 111 Processing Input from Forms 112 Dealing With Errors 115 Dynamically Acquiring Content 115 Using Python Expressions from DTML 117 DTML Expression Gotchas 119 will call the method. However, 119 Common DTML Tags 120 The Var Tag 120 Var Tag Attributes 120 Var Tag Entity Syntax 121 The If Tag 121 Here's an example condition: 121 Name and Expression Syntax Differences 122 Else and Elif Tags 122 Using Cookies with the If Tag 123 The In Tag 124 Iterating over Folder Contents 124 In Tag Special Variables 125 Summary 127 Using Zope Page Templates 128 Zope Page Templates versus DTML 128 How Page Templates Work 128 5 The Zope Book (2.6 Edition) Creating a Page Template 129 Simple Expressions 130 Inserting Text 130 Repeating Structures 131 Conditional Elements 132 Changing Attributes 133 Creating a File Library with Page Templates 133 Remote Editing with FTP and WebDAV 136 Debugging and Testing 137 XML Templates 138 Using Templates with Content 138 Creating Basic Zope Applications 140 Building "Instance-Space" Applications 140 Instance-Space Applications vs. Products 140 Using A Folder as A Container For Your Intstance-Space Application 140 Using Objects as Methods Of Folders Via URLs 141 Using Acquisition In Instance-Space Applications 141 The Special Folder Object index_html 141 Building the Zope Zoo Website 142 Navigating the Zoo 142 Adding a Front Page to the Zoo 144 Improving Navigation 145 Factoring out Style Sheets 147 Creating a File Library 148 148 Building a Guest Book 150 Extending the Guest Book to Generate XML 153 The Next Step 154 Users and Security 155 Introduction to Zope Security 155 Review: Logging In and Logging Out of the Zope Management Interface 155 Zope's "Stock" Security Setup 155 Identification and Authentication 156 Authorization, Roles, and Permissions 156 Managing Users 157 Creating Users in User Folders 157 Editing Users 159 6 The Zope Book (2.6 Edition) Defining a User's Location 159 Working with Alternative User Folders 160 Special User Accounts 160 Zope Anonymous User 161 Zope Emergency User 161 Creating an Emergency User 162 Zope Initial Manager 163 Protecting Against Password Snooping 163 Managing Custom Security Policies 164 Working with Roles 164 Defining Global Roles 164 Understanding Local Roles 165 Understanding Permissions 165 Defining Security Policies 166 Security Policy Acquisition 167 Security Usage Patterns 168 Security Rules of Thumb 168 Global and Local Policies 168 Delegating Control to Local Managers 168 Different Levels of Access with Roles 169 Controlling Access to Locations with Roles 170 Performing Security Checks 170 Advanced Security Issues: Ownership and Executable Content 172 The Problem: Trojan Horse Attacks 172 Managing Ownership 172 Roles of Executable Content 173 Proxy Roles 174 Summary 174 Advanced DTML 176 How Variables are Looked up 177 DTML Namespaces 178 DTML Client Object 179 DTML Method vs. DTML Document 180 DTML Request Object 180 Rendering Variables 181 Modifying the DTML Namespace 181 In Tag Namespace Modifications 181 7 The Zope Book (2.6 Edition) Additional Notes 182 The With Tag 182 The Let Tag 183 DTML Namespace Utility Functions 184 DTML Security 185 Safe Scripting Limits 186 Advanced DTML Tags 186 The Call Tag 186 The Comment Tag 187 The Tree Tag 188 The Return Tag 190 The Sendmail Tag 190 The Mime Tag 191 The Unless Tag 192 Batch Processing With The In Tag 193 Exception Handling Tags 195 The Raise Tag 195 The Try Tag 195 The Try Tag Optional Else Block 197 The Try Tag Optional Finally Block 197 Other useful examples 198 Forwarding a REQUEST 198 Sorting with the tag 198 Calling a DTML object from a Python Script 199 Explicit Lookups 199 Conclusion 199 Advanced Page Templates 200 Advanced TAL 200 Advanced Content Insertion 200 Inserting Structure 200 Dummy Elements 200 Default Content 201 Advanced Repetition 201 Repeat Variables 201 Repetition Tips 202 Advanced Attribute Control 203 Defining Variables 203 8 The Zope Book (2.6 Edition) Omitting Tags 204 Error Handling 204 Interactions Between TAL Statements 205 Form Processing 207 Expressions 208 Built-in Page Template Variables 208 String Expressions 209 Path Expressions 210 Alternate Paths 210 Not Expressions 211 Nocall Expressions 211 Exists Expressions 211 Python Expressions 212 Comparisons 212 Using other Expression Types 212 Getting at Zope Objects 213 Using Scripts 214 Calling DTML 214 Python Modules 215 Macros 215 Using Macros 216 Macro Details 216 Using Slots 217 Customizing Default Presentation 218 Combining METAL and TAL 219 Whole Page Macros 219 Caching Templates 220 Page Template Utilities 221 Batching Large Sets of Information 221 Miscellaneous Utilities 223 Conclusion 223 Advanced Zope Scripting 224 Zope Scripts 224 Here is an overview of Zope's scripts: 224 Calling Scripts 224 Context 225 Calling Scripts From the Web 225 9 The Zope Book (2.6 Edition) URL Traversal and Acquisition 226 Passing Arguments with an HTTP Query String 226 Calling Scripts from Other Objects 226 Calling Scripts from DTML 226 Calling scripts from Python and Perl 227 Calling Scripts from Page Templates 228 Calling Scripts: Summary and Comparison 229 Using Python-based Scripts 230 The Python Language 230 Creating Python-based Scripts 230 Binding Variables 232 Accessing the HTTP Request 233 String Processing in Python 234 Doing Math 234 Print Statement Support 235 Built-in Functions 236 Using External Methods 236 Processing XML with External Methods 241 External Method Gotchas 242 Using