更容易处理z3c.pagelet

gocept.pagelet的Python项目详细描述


gocept.pagelet

z3c.pagelet处理更简单

版权所有(c)2007-2016 Gocept GmbH&Co.KG 保留所有权利

本软件受Zope公共许可证的约束, 版本2.1(zpl)。此发行版应附带ZPL的副本。 本软件按“原样”提供,任何及所有明示或暗示的 不作任何保证,包括但不限于 所有权、适销性、侵权和适用性保证 为了特定的目的。

Changes

1.1 (2019-06-10)

  • 声明支持python 3.5、3.6、3.7、3.8、pypypy和pypy3。
  • 用毒物测试。

1.0 (2016-04-06)

  • 将bootstrap.py更新为zc.buildout 2.3
  • 使用py.test作为测试运行程序。
  • 声明对Python2.7的显式支持。 目前不支持其他python版本。

0.4 (2013-03-28)

  • 当使用仅具有模板的zcml注册pagelet时, 模板在repr中呈现,生成的类具有 在调试时了解这个类的用途。
  • 更新测试以使用python的doctest而不是弃用 zope.testing.doctest

0.3 (2009-12-27)

  • 使用zope.browserpagezope.browsermenu而不是 zope.app.publisher

0.2 (2009-12-27)

  • 允许任意数量的上下文元素进行调整。

0.1 (2008-09-20)

  • 首次公开发行。

Contributors

  • 迈克尔·霍维茨(Michael Howitz)<;mh在gocept dot com>;
  • Christian Theune<;CT位于Gocept Dot com>;

Easy z3c.pagelet registration

<;gocept:pagelet>;指令允许更轻松地注册 z3c.pagelets.它的行为非常类似于<;browser:page>;

Setup

我们需要一些zcml设置:

>>> import sys
>>> from zope.configuration import xmlconfig
>>> import gocept.pagelet
>>> context = xmlconfig.file('meta.zcml', gocept.pagelet)

Template only

可以将模板用作pagelet。不需要上课:

>>> context = xmlconfig.string("""
... <configure
...     xmlns:gocept="http://namespaces.gocept.com/zcml">
...   <gocept:pagelet
...       name="index.html"
...       for="*"
...       permission="zope.Public"
...       template="test-template.pt"
...       />
... </configure>
... """, context)

我们现在应该有一个页面:

>>> import zope.component
>>> from zope.publisher.browser import TestRequest
>>> pagelet = zope.component.getMultiAdapter(
...     (object, TestRequest()), name='index.html')
>>> pagelet
<gocept.pagelet.zcml.SimplePagelet from .../gocept/pagelet/test-template.pt object at 0x...>
>>> pagelet.__name__
u'index.html'

当我们呈现页面时,使用测试模板:

>>> pagelet.render()
u'Hello from the test template.\n'

Class only

当然,也可以在没有模板的情况下注册类。创建 在模块中初始化并使其可用:

>>> from z3c.pagelet.browser import BrowserPagelet
>>> class MyPagelet(BrowserPagelet):
...     """Custom pagelet"""
...     def render(self):
...         return u"Hello from the custom pagelet."""

把它放在假的包裹里custom

>>> sys.modules['custom'] = type(
...     'Module', (),
...     {'MyPagelet': MyPagelet})()

通过ZCML提供:

>>> context = xmlconfig.string("""
... <configure
...     xmlns:gocept="http://namespaces.gocept.com/zcml">
...   <gocept:pagelet
...       name="class.html"
...       for="*"
...       permission="zope.Public"
...       class="custom.MyPagelet"
...       />
... </configure>
... """, context)

获取页面:

>>> pagelet = zope.component.getMultiAdapter(
...     (object, TestRequest()), name='class.html')
>>> pagelet
<gocept.pagelet.zcml.MyPagelet object at 0x...>
>>> pagelet.render()
u'Hello from the custom pagelet.'

Class and template

当然也可以同时指定类和模板。所以创造 另一个Pagelet类并注册:

>>> class MyPagelet2(BrowserPagelet):
...     """Custom pagelet"""
...     i_am_very_custom = True
>>> sys.modules['custom'] = type(
...     'Module', (),
...     {'MyPagelet': MyPagelet2})()

通过ZCML提供:

>>> context = xmlconfig.string("""
... <configure
...     xmlns:gocept="http://namespaces.gocept.com/zcml">
...   <gocept:pagelet
...       name="class-template.html"
...       for="*"
...       permission="zope.Public"
...       class="custom.MyPagelet"
...       template="test-template.pt"
...       />
... </configure>
... """, context)
>>> pagelet = zope.component.getMultiAdapter(
...     (object, TestRequest()), name='class-template.html')
>>> pagelet
<gocept.pagelet.zcml.MyPagelet2 object at 0x...>
>>> pagelet.render()
u'Hello from the test template.\n'
>>> pagelet.i_am_very_custom
True

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Android同步不同页面上的按钮   java评测每个类收集的垃圾对象实例数   java(Spring MVC+Hibernate 4+Test 4)自动连线DAO返回NULL   java Android编辑文本和虚拟键盘   java Selenium与BrowserMobProxy   JAVAlang.NoClassDefFoundError:com/sun/jersey/spi/inject/Errors$关闭原因?   java为什么在我成功登录后仍然会出现“不正确的帐户或密码或用户类型”   安卓应用程序在重新启动java时崩溃。网UnknownHostException:无法解析主机   多线程在Java中同步共享静态对象的正确方法是什么?   未调用自定义注释的java类验证(约束类)   java如何将指定目录的存档文件放入所需位置?   java如何识别Selenium中的每个编辑文本字段,如果它们的Xpath都相同   使用gwtmockito/mockito的java简单单选按钮单元测试?