Zope简介

之前一直使用Django在开发web应用, 觉得Django易学, 好用. 后来看到Zope, 觉得两者的scope有重合, 所以大概学习了下Zope, 记录一下.

了解Zope可以先看看这篇Blog, zope系列一: zope的悲剧 (http://www.douban.com/group/topic/11400495/)

Zope(Z Object Publishing Environment)是一个企业级的web应用服务器的开发平台, 它很强大, 也比较复杂, 所以从某种程度上而言, 它无法被Python社区所接受, 因为它不够简单和美丽, 而python的哲学是大道至简. 由于推广问题, 策略问题, 等等问题导致这样一个平台没有红起来, 但是毋庸置疑它很牛, 很值得学习, 因为基于它开发出了Plone (Plone是免费的、开放源代码的内容管理系统(Content Management System,CMS)), 我个人没用过, 据说相当强大, 相当牛...所以我就先简单学习一下, 等以后用到再仔细研究吧.

以下内容来自Zope Book,

Fundamental Zope Concepts

Object Orientation
Unlike common file-based Web templating systems such as ASP or PHP, Zope is a highly "object-oriented" Web development platform.
Zope不同于其他web开放框架的是, 他不是基于文件的, 之前我们在使用jsp, 或django, 都是基于文件的, 而Zope是完全基于对象的, 任何东西, 网页模板, 逻辑代码, 数据都抽象为对象.

Object Publishing
The technology that would become Zope was founded on the realization that the Web is fundamentally object-oriented.
A URL to a Web resource is really just a path to an object in a set of containers, and the HTTP protocol provides a way to send messages to that object and receive its response.
既然基于对象, 所以就是基于对象的发布, 任何URL都是访问某一对象, 或发送message给某对象. 而不象一般的开放框架, 是基于文件发布的.

Through-The-Web Management
To create and work with Zope objects, you use your Web browser to access the Zope management interface. All management and application development can be done completely through the Web using only a browser.
这点是Zope很牛比的地方, 你只需要通过浏览器去访问Zope服务器, 就能完成任何服务器的管理, 更牛的是, 你还可以完成应用的开发. 可以想象, 只需要一台Zope服务器, 你可以在任何地方方便的管理并开发应用. 多么美好的场景.

Security and Safe Delegation
One of the things that sets Zope apart from other application servers is that it was designed from the start to be tightly coupled not only with the Web object model, but also the Web development model. Today's successful Web applications require the participation of many people across an organization who have different areas of expertise. Zope is specifically designed to accommodate this model, allowing site managers to safely delegate control to design experts, database experts and content managers.
Objects in Zope provide a much richer set of possible permissions than a conventional file-based system. Permissions vary by object type based on the capabilities of that object. This makes it possible to implement fine-grained access control.
对于一个大型的Web应用而言, 需要很多角色的开发者, 当他们协同开发的时候, 出于安全性和可维护性的考虑, 需要分配不同的权限, Zope对这个也有很好的支持.

Native Object Persistence and Transactions
Zope objects are stored in a high-performance transactional object database known as the Zope Object Database (ZODB). Each Web request is treated as a separate transaction by the object database.The Zope framework makes all of the details of persistence and transactions totally transparent to the application developer.The Zope framework makes all of the details of persistence and transactions totally transparent to the application developer.
Zope Object Database (ZODB), Zope不但提供开放框架, 还提供了一套面向对象数据库的solution来支持它的面向对象发布, 而其他开发框架往往都是基于现有的关系数据库.
据说这个数据库很好用, 很牛比, 现在流行的No Sql数据库都没这个牛, 没研究过, 没发言权.
等后面有空了, 来好好研究一下这个数据库.

Acquisition
One of the most powerful aspects of Zope is "Acquisition", and the core concept is simply that:
 ·  Zope objects are contained inside other objects (such as Folders).
 ·  Objects can "acquire" attributes and behavior from their containers.
这个是Zope在它的对象层次架构上的一个创新, 这个概念是Zope发明的, 以前没有听说过. 其实很简单, 就是基于包含(contain)关系的功能继承.
说白了, Object可以继承container的behavior. 这非常适合Zope的对象层次架构, 很像文件系统, 一级一级不断的包含下去, 所以非常便于service的提供和发布.

Zope Is Extensible
Zope is highly extensible, and advanced users can create new kinds of Zope objects, either by writing new Zope add-ons in Python or by building them completely through the Web. 

 

Fundamental Zope Components

下面列出Zope的架构图,

ZServer — Zope comes with a built in web server that serves content to you and your users. This web server also serves Zope content via FTP, WebDAV, and XML-RPC (a remote procedure call facility).
Web Server — Of course, you may already have an existing web server, such as Apache or Microsoft IIS and you may not want to use Zope's. Zope works with these web servers also, and any other web server that supports the Common Gateway Interface (CGI).
Zope本身就提供ZServer, 如果你喜欢用其他的Server, 如Apache...随便

Zope Core — This is the engine which coordinates the show, driving the management interface and object database.
这个就是核心engine, 用来run这个Zope server

Object Database — When you work with Zope, you are usually working with objects that are stored in Zope's object database.
Relational database — You don't have to store your information in Zope's object database if you don't want to. Zope works with other relational databases such as Oracle , PostgreSQL , Sybase , MySQL and others.
File System — Zope can of course work with documents and other files stored on your server's file system.
Zope开发了很牛比的面向对象数据库, 你可以把一齐都当对象存进去. 当然你如果想用, 关系型数据库和文件系统, 也没问题.

ZClasses — Zope allows site managers to add new object types to Zope using the Zope Management Interface. ZClasses are these kinds of objects.
Products — Zope also allows site managers to add new object types to Zope by installing "Product" files on their Zope server's filesystem.

 

Using Basic Zope Objects

对于Zope的核心就是对象, 下面就来介绍一下Zope对象, 这就是典型的MVC架构...
In general, basic Zope objects take on one of three types of roles:

Content — Zope objects such as documents, images and files hold different kinds of textual and binary data. In addition to objects in Zope containing content, Zope can work with content stored externally, for example, in a relational database.


Presentation — You can control the look and feel of your site with Zope objects that act as web page "templates". Zope comes with two facilities to help you manage presentation: DTML (which also handles "logic"), and Zope Page Templates (ZPT). The difference between DTML and ZPT is that DTML allows you to mix presentation and logic, while ZPT does not.

Logic — Zope has facilities for scripting business logic. Zope allows you to script behavior using three facilities: Document Template Markup Language (DTML), Python, and Perl (Perl is only available as an add-on).

Content Objects: Folders, Files, and Images

Folders
You've already met one of the fundamental Zope objects: the Folder . Folders are the building blocks of Zope. The purpose of a folder is simple: a Folder's only job in life is contain other objects.Folders can contain any other kind of Zope object, including other folders. You can nest folders inside each other to form a tree of folders. Good structure is very important, as Zope security and presentation is influenced by your site's folder structure.

Files
Zope Files contain raw data, just as the files on your computer do. Files do not consider their contents to be of any special format, textual or otherwise. Every File object has a particular content type which is a standard Internet MIME designation for types of content.

Images
Image objects contain the data from image files such as GIF, JPEG, and PNG files.

Presentation Objects: Zope Page Templates and DTML Objects

Zope Page Templates are objects which allow you to define dynamic presentation for a web page. The HTML in your template is made dynamic by inserting special XML namespace elements into your HTML which define the dynamic behavior for that page.
<title tal:content="here/title">Page Title</title>


Document Template Markup Language objects are object which also allow you to define presentation for a web page. The HTML in your template is made dynamic by inserting special "tags" (directives surrounded by angle brackets, typically) into your HTML with define the dynamic behavior for that page.
<dtml-in mySequence>
    <!-- this is an HTML comment inside the in tag block -->
</dtml-in>

Both ZPT and DTML are "server-side" scripting languages, like SSI, PHP, embperl, or JSP. This means that DTML and ZPT commands are executed by Zope on the server, and the result of that execution is sent to your web browser.

Zope's original dynamic presentation language was DTML. It soon became apparent that DTML was great at allowing programmers to quickly generate dynamic web pages, but many times failed at allowing programmers to work effectively together with nontechnical graphics designers. Thus, ZPT was born. ZPT is an "attribute-based" presentation language that tries to allow for the "round-trippping" of templates between programmers and nontechnical designers.

大家是否都觉得, 为什么需要两个View solution, 是啊, 这就是Zope灵活的地方, 你想怎么用就怎么用, 但是这就违反了python的简单原则, 对于一个问题, 最好只有唯一的答案, 太多选择有时候也是件烦恼的事.上面也说了, 本来是只有DTML的, 它很灵活, 适用于开发者, 不但可以开放view, 里面可以加上logic, 这样虽然影响MVC分层的理念, 但只要做过相关开发都应该体会到, 绝对的分开view和logic,有时候是很麻烦的, 很不实用的, 虽然看上去很美. 他最大的问题就是, 直接在Html增加Tag, 这样开发的view是无法直接用浏览器预览的,因为他的结果非标准Html, 有很多自定义的Tag. 这样就无法和UI设计人员合作开发, 你无法要求UI人员熟悉使用DTML, 而他用HTML设计的UI模板, 在DTML里无法直接使用.
所以产生了 Zope Page Templates (ZPT ), 它只会在Html属性上加上特殊的XML命名空间, 这样是不影响网页被浏览器预览的, 这样就解决了刚才的问题, 不过ZPT不允许插入任何逻辑, 对于开发人员而言不是那么方便, 各有所长, 爱用谁用谁......

Logic Objects: Script (Python) Objects and External Methods

"Logic" objects in Zope are objects which typically perform some sort of "heavy lifting" or "number crunching" in support of presentation objects.

 

Acquisition


Acquisition is the technology that allows dynamic behavior to be shared between Zope objects via containment .
Acquisition's flavor permeates Zope. It can be used almost everywhere within Zope: in DTML, in Zope Page Templates, in Script (Python) objects, and even in Zope URLs. Because of its ubiquity in Zope, a basic understanding of acquisition is important.

Acquisition vs. Inheritance

Inheritance stipulates that an object can learn about its behavior from its superclasses via an inheritance hierarchy .
Acquisition , on the other hand, stipulates that an object can additionally learn about its behavior its through its containment hierarchy . In Zope, an object's inheritance hierarchy is always searched for behavior before its acquisition hierarchy. If the method or attribute is not found in the object's inheritance hierarchy, the acquisition hierarchy is searched.

 

 

你可能感兴趣的:(object,database,hierarchy,inheritance,templates,behavior)