创建灵巧内容的类grok指令
plone.directives.dexterit的Python项目详细描述
plone.directives.dexterity
这个包提供了可选的、类似grok的指令来配置 灵巧的内容。这取决于5。格罗克,这又取决于 各种可重用的grokcore.*包,但不是grok本身。
另请参见plone.directives.form,它提供了用于配置的指令 模式与表单提示接口。
内容类
扩展灵活的“item”和“container”基类的内容可以是 为了注册工厂和/或zmi add权限而摸索。
例如:
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()”指令使类型 注册为Zope2内容类,与 <;five:registerClass/>;指令执行:
class ZopeTwoItem(dexterity.Item): grok.implements(IPage) dexterity.add_permission('cmf.AddPortalContent') portal_type = 'example.zopetwopage'
但是,对于大多数内容类型,这是不必要的。
表格
若要为类型创建灵活的“添加”、“编辑”或“显示”窗体,请使用 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() 指令来指定添加视图的名称。通常,这和 工厂类型信息对象的名称。
- 使用dexterity.EditForm作为基时,必须使用grok.context() 并提供一个灵活的内容类型接口作为参数。这是为了 允许正确重用类型。
更改日志
1.0.2-2011年9月25日
- 在^{tt5}中修复super()调用$ [大卫萨格里]
1.0.1-2011年9月24日
- 遵守add forms上的plone.directives.form.wrap指令。 默认情况下,它们保持包装,以便与自定义 模板。 这将关闭http://code.google.com/p/dexterity/issues/detail?id=184 [大卫萨格里]
1.0-2011年5月20日
- 修好休息。 [大卫萨格里]
1.0b1-2010-08-05
- 确保自定义添加表单在创建后重定向到正确的位置 内容。修复http://code.google.com/p/dexterity/issues/detail?id=136 [选项]
1.0a2-2009年11月17日
- 修复Zope2.12上的弃用警告 [选项]
1.0A1-2009-07-25
- 初始版本