个人工具
登录
查看“简单的TODO应用程序”的源代码 - Ubuntu中文
页面
讨论
查看源代码
历史
搜索
导航
首页
最近更改
随机页面
页面分类
帮助
编辑
编辑指南
沙盒
新闻动态
字词处理
工具
链入页面
相关更改
特殊页面
页面信息
查看“简单的TODO应用程序”的源代码
来自Ubuntu中文
←
简单的TODO应用程序
跳转至:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
==== Step 1: Basic interfaces and classes(步骤1:基本接口和类) ==== A significant design choice of Zope 3 is that it's interface driven. Interfaces are used not only to document, but to adapt. Interfaces are Zope 3's type system. Unlike class based types, anything can implement them or adapt to them, and all proper code in the Zope 3 system should ask for an interface implementation for a given object.<br>Zope 3 的一个重要设计就是它的接口驱动。接口不仅用于文档,也用于适配。接口是 Zope 3 的类型系统。不象基于类型的类,任何东西都可以实现或适配它们,并且在 Zope 3 系统中的所有适用代码都可以请求一个接口以实现给定的对象。 Interface design has been taken beyond basic method definitions to include object schema and even pre / post conditions. This data can be introspected to build user interfaces, which is how much of the standard Zope 3 management interface gets built. In fact, I'll show how this is done next in the series.<br>接口设计已经超过基本方法定义,包括对象 schema,甚至是预设/提交条件。该数据能够被自省以构建用户接口,它是众多得到构建标准 Zope 3 管理接口之一。实际上,我将展示如何在一系列接口中生成下一个。 So the basic todo application uses the following interfaces. These are just the basic model objects. The Todo List is just a container that only contains items that implement the ITodo interface. A Todo doesn't do much beyond store some simple data. So here they are, from the file interfaces.py in the package todo: <br>因此基本 todo 应用程序使用下列接口。这只是基本模型对象。 Todo 列表只是一个包含实现 ITodo 接口项的容器。Todo 除了保存一些简单数据外并不做其它。因此在包 todo 中的 interfaces.py 文件中如下所示: <pre><nowiki>#!/usr/bin/env python from zope.interface import Interface import zope.schema # These will aid in making a special "todo" container by specifying the # constraint in the interface. from zope.app.container.constraints import ItemTypePrecondition from zope.app.container.interfaces import IContained, IContainer class ITodo(Interface): """ A todo item doesn"t need to do much... """ description = zope.schema.TextLine( title=u"To Do", required=True, ) details = zope.schema.Text( title=u"Details", required=False, ) done = zope.schema.Bool(title=u"Done") class ITodoList(IContainer): """ A todo list contains todo objects. """ def <u>setitem</u>(name, object): """ Add an ITodo object. """ <u>setitem</u>.precondition = ItemTypePrecondition(ITodo) </nowiki></pre> The implementation is even simpler. Since this is a small application, I put the implementation in `todo/<u>init</u>.py`: <br> 实现甚至更简单。因为这是个小应用程序,所以我把实现放到了 `todo/<u>init</u>.py` 文件中: <pre><nowiki>#!/usr/bin/env python from zope.interface import implements from zope.app.container.btree import BTreeContainer from persistent import Persistent from interfaces import ITodoList, ITodo class TodoList(BTreeContainer): implements(ITodoList) class Todo(Persistent): implements(ITodo) description = u"" details = u"" done = False </nowiki></pre> And that's it. Really! Now what needs to be done next is to wire these into Zope 3. But already, one can see that this is much simpler than what one might have to do to write some data objects for Zope 2. <br> 就这样。真的!现在下一步需要做的就是将这样写到 Zope 3 中。这看起来比为 Zope 2 编写一些数据对象要简单得多。
返回至
简单的TODO应用程序
。