三十分钟学会Zope3(已完成,请参阅本站 Wiki)

软件和网站开发以及相关技术探讨
头像
firehare
帖子: 2625
注册时间: 2005-04-10 16:54
来自: 温州大学
联系:

三十分钟学会Zope3(已完成,请参阅本站 Wiki)

#1

帖子 firehare » 2005-10-12 21:37

Zope3 In 30 Minutes
三十分钟学会Zope3
Author: Baiju M <baiju.m.mail AT gmail.com>
Version: 0.1.4
Copyright: (C) 2005 Baiju M, Placed under GNU GPL version 2, or (at your option) any later version
翻译:firehare
校正:leal
组织:ubuntu.org.cn

Contents
目录
* Why 30? 为什么是30分钟
* And why should I ...? 为什么我要学...
* Keywords 关键词
* So let's start... 那么让我们开始
* BookMarker : Your first Zope3 app BookMarker:你的第一个Zope3应用
* Interfaces 接口
* Unit Testing 单元测试
* Real coding! 正式编码
* Configuration 配置
* Just run it
* Views 视图
* Functional testing 功能测试
* Now what? 现在学什么?

Important Note: I assume you are using Debian 3.1 (Sarge) or similar systems.
特别注意:我假设你正在使用Debian3.1(Sarge)或相似系统
上次由 firehare 在 2006-01-18 8:19,总共编辑 9 次。
我心无畏,源自于我心无知。
图片
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
联系:

#2

帖子 leal » 2005-10-12 21:46

动作好快啊 呵呵
用心×恒 | 豆瓣 | 门户 | Blog
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#3

帖子 eexpress » 2005-10-12 21:52

都没说明是什么东西。别人怎么敢学。
● 鸣学
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
联系:

#4

帖子 leal » 2005-10-12 21:53

估计在这儿啦
* And why should I ...? 为什么我要学...
用心×恒 | 豆瓣 | 门户 | Blog
头像
firehare
帖子: 2625
注册时间: 2005-04-10 16:54
来自: 温州大学
联系:

#5

帖子 firehare » 2005-10-12 22:00

Why 30?
为什么是30分钟

Sorry! Zope3 cannot be introduced in 10 minutes.
很抱歉!Zope3是不可能在10分钟内介绍清楚的

And why should I ...?
为什么我要学?

If you are looking for a Pythonic framework for web application development, just continue reading. And I am not going to make a new definition for What is Pythonic? :) . Here I will try to answer your "why?" questions.
如果你想为基于Web的应用开发作一个Pythonic的框架,那么请继续。我并不打算对什么是Pythonic作任何新的解释:),主要试图回答“为什么”的问题。

Keywords
关键词

Python, Zope, Interface, Component, ZCML, ZMI, Adapter, View, Event, Service, Utility, Principal.

So let's start...
那么让我们开始...

Zope3 is the third generation of Zope, a framework for web applications. You can download Zope 3.1 from http://www.zope.org/Products/Zope3 . To install untar Zope3 source package, then as root:
Zope3是第三代的Zope,一个Web应用框架。你可以从http://www.zope.org/Products/zope3下载Zope3.1,解压Zope3源包,并以根用户权限运行:

代码: 全选

# cd Zope-3.1.0
# ./configure;make;make install
译者的话:
如果是在Ubuntu下,请按下面命令运行:

代码: 全选

$tar -zxvf Zope-3.1.0.tgz -C /tmp
(如果是Breezy下,请安装Python2.3 Python2.3-dev等相关包,因为Zope3是基于Python2.4.1和Python2.3.5开发的,而Breezy默认是Python2.4.2,所以必须安装Python2.3的包文件了)
$./configure --prefix /opt/zope
$make
$make check
$make install
After installation you have to make an instance (don't worry! just do it). To do so:
安装完成后,你必须建立一个Zope Instance(别担心!只需照作就行)。命令如下:

代码: 全选

$ cd /usr/local/Zope-3.1.0/bin
$ ./mkzopeinstance --dir=$HOME/myzope --user=admin:secret123
To start Zope3 server, go to your instance directory, then:
然后是启动你的Zope3服务,到你的Instance目录下,然后运行:

代码: 全选

$ cd ~/myzope
$ ./bin/runzope
If you get a port error, check check 8080 and 8021 is already used by other programs; for the time being, just stop it. Start your browser , the open http://localhost:8080 . What you see is the Zope Management Interface (ZMI). ZMI is your Python prompt, hmm... no! Zope prompt, got it?. You can login and look around to see what's happening. If you played enough with ZMI, stop it from terminal (Control + C).
如果你得到一个端口错误,请检查8080和8021端口是否被其他程序占用;暂时停止运行该程序。打开你的浏览器,然后输入http://localhost:8080。你将看到Zope Management Interface(ZMI)。ZMI是你的Python提示符,嗯...不!应该是Zope的提示符,看到了吗?你可以登录进去并且到处点击看看。如果你在ZMI玩够了的话,在终端用Ctrl+C中断它。
上次由 firehare 在 2005-10-12 22:34,总共编辑 4 次。
我心无畏,源自于我心无知。
图片
头像
firehare
帖子: 2625
注册时间: 2005-04-10 16:54
来自: 温州大学
联系:

#6

帖子 firehare » 2005-10-12 22:01

leal 写了:估计在这儿啦
* And why should I ...? 为什么我要学...
leal兄帮忙看看,我的E文不好,呵呵!
我心无畏,源自于我心无知。
图片
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
联系:

#7

帖子 leal » 2005-10-12 22:15

great!已经翻译的很好了 :),有几个地方觉得改一改能更好 :o
If you are looking for a Pythonic framework for web application development, just continue reading. And I am not going to make a new definition for What is Pythonic? Smile . Here I will try to answer your "why?" questions.
如果你想为基于Web的应用开发打一个Python化的框架,那么请继续。我并不打算对什么是Python化作任何解释Smile,我只是在这里回答“为什么”的问题。
如果你正在寻找一个web应用开发的Pythonic(Python化、式,觉得保留原文,第一次出现时做一定注释就好,毕竟这个词在Python世界也算较通用的了)框架,……此处我不打算对Pythonic一词做重新定义(任何新的解释、定义?),主要试图回答……
After installation you have to make an instance (don't worry! just do it). To do so:
然后安装你需要安装一个Instance(别担心!只需照作就行)。命令如下:
安装完成后,你必须建立一个instance(Zope Instance)……
用心×恒 | 豆瓣 | 门户 | Blog
头像
firehare
帖子: 2625
注册时间: 2005-04-10 16:54
来自: 温州大学
联系:

#8

帖子 firehare » 2005-10-12 22:28

BookMarker : Your first Zope3 app
BookMarker:你的第一个Zope3应用

Yes! we are going to create a Zope3 application, an online book marker. Our app will display links to websites and a description for each link.
是的!我们打算开始创建一个Zope3应用,一个在线书签。我们的应用将显示到网站的链接和每条链接的描述。

So, what you have to think about when you start a Zope3 project. Oh! sorry! I can't put it in one sentence, you better learn and practice Extreme Programming http://en.wikipedia.org/wiki/Extreme_programming. Anyway, after your initial design, you will write interfaces. Let us hope Python 3.0 will make it much easier. Then you will write unit tests, now your ideas become very concrete!. At last write your real code. You will be satisfied when you implement interfaces one by one and unit tests succeeds!. I have given the source code of BookMarker here: boom.tar.bz2
那么,在开始一个Zope3项目前,你得做何准备呢?哦!很抱歉!我没法一言以蔽之,你最好先学习并实践XP(极限编程,一种轻量级的软件开发过程)http://en.wikipedia.org/wiki/Extreme_programming。总之,在你初步设计之后,就将编写接口。让我们期待Python 3.0 会让它变得容易些吧!然后开始编写单元测试,至此你的想法已非常具体!最后编写正式代码。当你一个接一个的实现接口并通过单元测试,你会拥有(前所未有的)满足感! 我已经在这里给出了BookMarker应用的源代码:boom.tar.bz2

Our code will be placed at $HOME/myzope/lib/python/boom
我们的代码将放在$HOME/myzope/lib/python/boom目录中

First create a file interfaces.py where we will keep our interfaces. Later we will implement these interfaces one by one, with strong support of unit testing.
首先创建一个interfaces.py的文件,我们将在该文件内保存所有接口。后面我们将在单元测试的强力支持下,一个接一个的实现这些接口。
上次由 firehare 在 2005-10-12 23:14,总共编辑 3 次。
我心无畏,源自于我心无知。
图片
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
联系:

#9

帖子 leal » 2005-10-12 22:45

BookMarker为程序(应用)名,不译为好。
So, what you have to think about when you start a Zope3 project. Oh! sorry! I can't put it in one sentence, you better learn and practice Extreme Programming http://en.wikipedia.org/wiki/Extreme_programming. Anyway, after your initial design, you will write interfaces. Let us hope Python 3.0 will make it much easier. Then you will write unit tests, now your ideas become very concrete!. At last write your real code. You will be satisfied when you implement interfaces one by one and unit tests succeeds!. I have given the source code of BookMarker here: boom.tar.bz2
那么,你一定在想你什么时候开始一个Zope3项目了。哦!很抱歉!我并不能把它放在一个语句里(感觉这句好象是一句俗语或类似成语的东东,先直译吧,反正大体意思大家也能理解),你最好还是先学习和练习一下一个Extreme程序 http://en.wikipedia.org/wiki/Extreme_programming. 总之在你初步设计之后,你将会编写接口。让我们期待Python 3.0会使它更容易些吧。然后你还要编写单元测试,这时,你的思路将变得非常实在!最后编写你的正式代码。当你完成一个个的接口而且又通过了单元测试后,你会觉得很满足的!我已经在这里给出了书签应用的源代码:boom.tar.bz2
那么,在开始一个Zope3项目前,你得做何准备呢?哦!很抱歉!我没法一言以蔽之,你最好先学习并实践XP(极限编程,一种轻量级的软件开发过程)http://en.wikipedia.org/wiki/Extreme_programming。总之,在你初步设计之后,就将编写接口。让我们期待Python 3.0 会让它变得容易些吧!然后开始编写单元测试,至此你的想法已非常具体!最后编写正式代码。当你一个接一个的实现接口并通过单元测试,你会拥有(前所未有的)满足感!……
Our code will be placed at $HOME/myzope/lib/python/boom
我们的代码将放在 $HOME/myzope/lib/python/boom文件夹内。
First create a file interfaces.py where we will keep our interfaces. Later we will implement these interfaces one by one, with strong support of unit testing.
首先创建一个interfaces.py的文件,在该文件里我们将保存我们的接口,随后我们将通过强大的单元测试来支持我们一个个地去实现这些接口。
首先,新建一个interfaces.py文件,我们将在该文件内保存所有接口。后面我们将在单元测试的强力支持下,一个接一个的实现这些接口。
上次由 leal 在 2005-10-12 23:01,总共编辑 1 次。
用心×恒 | 豆瓣 | 门户 | Blog
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
联系:

#10

帖子 leal » 2005-10-12 22:50

原文地址Zope3 In 30 Minutes

中国Zope用户组上的一些信息

zope3 是下一代的zope,正在组织翻译Zope3宝典

不过目前只翻译了标题。
用心×恒 | 豆瓣 | 门户 | Blog
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
联系:

#11

帖子 leal » 2005-10-12 23:02

* Just run it 仅要运行
* Views 界面
Just run it (只待运行了) 或者不译?
Views 视图? 或不译?
用心×恒 | 豆瓣 | 门户 | Blog
头像
firehare
帖子: 2625
注册时间: 2005-04-10 16:54
来自: 温州大学
联系:

#12

帖子 firehare » 2005-10-12 23:05

Interfaces
接口

Here is our interfaces.py:
下面就是我们的interfaces.py:

代码: 全选

from zope.interface import Interface
from zope.schema import Text, TextLine, Field

from zope.app.container.constraints import ContainerTypesConstraint
from zope.app.container.constraints import ItemTypePrecondition
from zope.app.container.interfaces import IContained, IContainer

class IMark(Interface):
    """This is the book mark object."""

    url = TextLine(
        title=u"URL/Link",
        description=u"URL of the website",
        default=u"http://www.zope.org",
        required=True)

    description = Text(
        title=u"Description",
        description=u"Description of the website",
        default=u"",
        required=False)

class IBookMarker(IContainer):
    """This is the container for all book marks."""

    name = TextLine(
        title=u"Name of BookMarker",
        description=u"A name for BookMarker",
        default=u"",
        required=True)

    def __setitem__(name, obj):
        pass

    __setitem__.precondition = ItemTypePrecondition(IMark)


class IMarkContained(IContained):
    """A book mark can only contain in a BookMarker"""

    __parent__ = Field(
        constraint = ContainerTypesConstraint(IBookMarker))
Our first interface IMark has two attributes, one is the URL of the site and the other one is the description. Please note, IMark is not a class even though we used Python's class definition. We inherited from Interface to make it an interface. Second one is a container interface, which is an extended IContainer interface. By using this container interface we can persist our data (instances of IMark implementations). We will put all objects of IMark in a container object of IBookMarker. We will implement IMark along with IMarkContained as a constraint interface. So that IMark object will be only contained in an IBookMarker object.
我们的第一个接口IMark有两个属性,一个是站点的URL,另 一个是它的描述。请注意,IMark不是一个类,尽管我们使用了Python的类定义。IMark继承自Interface,因此是个接口。第二个是一个容器接口,它是一个扩展的Icontainer接口。我们可以使用这个容器接口来保存我们的数据(IMark实现的实例)。我们将IMark的所有对象放到IBookMarker的一个容器对象里。我们连同IMarkContained(作为一个约束接口)一起来实现IMark。所以IMark对象只能包含在IBookMarker对象中。
上次由 firehare 在 2005-10-12 23:27,总共编辑 1 次。
我心无畏,源自于我心无知。
图片
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
联系:

#13

帖子 leal » 2005-10-12 23:06

Sorry! Zope3 cannot be introduced in 10 minutes.
很抱歉!Zope3是不可能在10分钟内介绍清楚的
抱歉!只因无法在10分钟内介绍清楚Zope3啊。

这样和标题能形成呼应,也更显俏皮一些 :)

供参考 ……
用心×恒 | 豆瓣 | 门户 | Blog
头像
firehare
帖子: 2625
注册时间: 2005-04-10 16:54
来自: 温州大学
联系:

#14

帖子 firehare » 2005-10-12 23:07

上面这段由于已经有点想睡了,所以感觉翻得不很畅,明天再继续了!:)
我心无畏,源自于我心无知。
图片
头像
firehare
帖子: 2625
注册时间: 2005-04-10 16:54
来自: 温州大学
联系:

#15

帖子 firehare » 2005-10-12 23:08

leal 写了:
firehare 写了:Sorry! Zope3 cannot be introduced in 10 minutes.
很抱歉!Zope3是不可能在10分钟内介绍清楚的
抱歉!只因无法在10分钟内介绍清楚Zope3啊。

这样和标题能形成呼应,也更显俏皮一些 :)

供参考 ……
有道理!立马修正过来,:)
上次由 firehare 在 2005-10-13 11:12,总共编辑 2 次。
我心无畏,源自于我心无知。
图片
回复