Personal tools
You are here: Home Zope Tutorials 30分钟学会zope3 增加用户界面

增加用户界面

Document Actions
添加视图、页面,增加功能测试代码

panjy

本文由firehare等翻译。 http://zissue.berlios.de/z3/Zope3In30Minutes.html
Page 3 of 4.

视图

现在新建一个名为browser.py的文件,并输入下列代码:

from boom.interfaces import IMark

class BookMarks:

    def __init__(self, context, request, base_url=''):
        self.context = context
        self.request = request
        self.base_url = base_url

    def listMarks(self):
        marks = []
        for name, child in self.context.items():
            if IMark.providedBy(child):
                info = {}
                info['url'] = child.url
                info['description'] = child.description
                marks.append(info)
        return marks

然后创建一个模板(marks.pt):

<html metal:use-macro="views/standard_macros/view">
  <body>
    <div metal:fill-slot="body">

      <div class="row">
        <div class="label">Book Marks:</div>
        <br/><br/>
          <li tal:repeat="item view/listMarks">

            <a href="" tal:attributes="href item/url">
               <span tal:content="item/url">Link</span>
            </a>
            <pre tal:content="item/description">Description</pre>
            <br/>

          </li>
      </div>

    </div>
  </body>
</html>

现在点击一下“Marks”标签,你就可以看到所有的书签了。

好的!这样可不能算是结束,这仅仅是你学习的开始。

功能测试

让我们为视图写一个功能测试来结束我们的例子(ftests.py):

import unittest
from zope.app.testing.functional import BrowserTestCase

class BookMarksTest(BrowserTestCase):

    def testMarksListing(self):
        pass


def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(BookMarksTest),
        ))

if __name__ == '__main__':
    unittest.main(defaultTest='test_suite')

然后运行该功能测试:

$ cd $HOME/myzope/lib
$ ../bin/test -vpf --dir boom

现在学什么?

现在你可以通过 Zope3 Book 开始详细学习Zope3了。也可以加入到zope3-user邮件列表里。

这里有Benji York写的一个不错的Zope3快速入门指南: http://www.benjiyork.com/quick_start/ 还有一本已出版的介绍性图书,很不错,请访问: http://worldcookery.com/

还有一点:我想不断完善这份文档,因此有何意见/建议千万别犹豫,请发送到: baiju.m.mail@gmail.com

by 潘俊勇 last modified 2005-10-15 01:49
Contributors: Author: Baiju M <baiju.m.mail AT gmail.com>, 翻译:firehare, 校正:leal, 组织:ubuntu.org.cn

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: