为创建Dexterity内容提供类似Grok的指令
项目描述
plone.directives.dexterity
此包提供可选的、类似Grok的指令,用于配置Dexterity内容。它依赖于five.grok,而five.grok又依赖于各种可重用的grokcore.*包,但不依赖于Grok本身。
另请参阅plone.directives.form,它提供了配置具有表单提示的schema接口的指令。
内容类
扩展Dexterity的‘Item’和‘Container’基类的内容可以被解析,以注册一个工厂和/或ZMI添加权限。
例如
from plone.directives import dexterity from plone.directives import form from five import grok from zope import schema class IPage(form.Schema): title = schema.TextLine(title=u"Title") description = schema.Text(title=u"Description", description=u"Summary of the body") body = schema.Text(title=u"Body text", required=False, default=u"Body text goes here") details = schema.Text(title=u"Details", required=False) class FSPage(dexterity.Item): grok.implements(IPage) grok.name('example.page') def __init__(self, id=None, title=None, description=None, body=None, details=None): self.id = id # required - or call super() with this argument self.title = title self.description = description self.body = body self.details = details
如果尚未存在具有名称‘example.fspage’的工厂实用工具,则这将注册一个工厂实用工具。
您还可以使用 'add_permission()' 指令将类型注册为 Zope 2 内容类,就像使用 <five:registerClass /> 指令一样。
class ZopeTwoItem(dexterity.Item): grok.implements(IPage) dexterity.add_permission('cmf.AddPortalContent') portal_type = 'example.zopetwopage'
然而,对于大多数内容类型,这将是多余的。
表单
要为您的类型创建 Dexterity 添加、编辑或显示表单,请使用 AddForm、EditForm 或 DisplayForm 基类。例如
from plone.directives import dexterity from plone.directives import form from five import grok from zope import schema class IPage(form.Schema): title = schema.TextLine(title=u"Title") description = schema.Text(title=u"Description", description=u"Summary of the body") body = schema.Text(title=u"Body text", required=False, default=u"Body text goes here") details = schema.Text(title=u"Details", required=False) class View(dexterity.DisplayForm): """The view. May will a template from <modulename>_templates/view.pt, and will be called 'view' unless otherwise stated. """ grok.require('zope2.View') grok.context(IPage) class Edit(dexterity.EditForm): """A standard edit form. """ grok.context(IPage) def updateWidgets(self): super(Edit, self).updateWidgets() self.widgets['title'].mode = 'hidden'
这些表单的处理方式与 plone.directives.form 类似,并支持自定义模板关联。请注意,但是
当使用 dexterity.AddForm 作为基础时,您必须使用 grok.name() 指令来给出添加视图的名称。通常,这和 Factory 类型信息对象的名称相同。
当使用 dexterity.EditForm 作为基础时,您必须使用 grok.context() 并提供一个 Dexterity 内容类型接口作为参数。这是为了允许类型的正确重用。
变更日志
1.0.2 - 2011-09-25
在 plone.directives.dexterity.AddForm 中修复 super() 调用 [davisagli]
1.0.1 - 2011-09-24
在添加表单上遵守 plone.directives.form.wrap 指令。为了与自定义模板保持向后兼容,它们默认情况下保持包装状态。这解决了 http://code.google.com/p/dexterity/issues/detail?id=184 [davisagli]
1.0 - 2011-05-20
修复 reST。 [davisagli]
1.0b1 - 2010-08-05
确保自定义添加表单在创建内容后重定向到正确的位置。修复了 http://code.google.com/p/dexterity/issues/detail?id=136 [optilude]
1.0a2 - 2009-11-17
修复 Zope 2.12 上的弃用警告 [optilude]
1.0a1 - 2009-07-25
首次发布
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。
源分发
plone.directives.dexterity-1.0.2.zip 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 502dff4e5b4f57c78e88849863b6e9757971477c32c2e61655f98c6b62e76b14 |
|
MD5 | 713b87644e3591b60b4a8ebd52987477 |
|
BLAKE2b-256 | 000824ab3c049600f3fc8875c04af5bd877dd6c50191f7cb015677bed6456389 |