Skip to main content

用于创建敏捷内容的类 Grok 指令

项目描述

plone.directives.灵巧

这个包提供了可选的、类似 Grok 的指令来配置 Dexterity 内容。它依赖于 Five.grok,而后者又依赖于各种可重用的 grokcore.* 包,而不是 Grok 本身。

另请参阅 plone.directives.form,它提供了用于配置带有表单提示的模式接口的指令。

内容类

扩展 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() 指令来给出添加视图的名称。通常,这与工厂类型信息对象的名称相同。

  • 当使用dexterity.EditForm作为基础时,您必须使用grok.context() 并提供一个 Dexterity 内容类型接口作为参数。这是为了允许正确重用类型。

变更日志

1.0.2 - 2011-09-25

  • 修复plone.directives.dexterity.AddForm [davisagli]中的 super() 调用

1.0.1 - 2011-09-24

1.0 - 2011-05-20

  • 修复休息。[达维萨利]

1.0b1 - 2010-08-05

1.0a2 - 2009-11-17

  • 修复 Zope 2.12 上的弃用警告 [optilude]

1.0a1 - 2009-07-25

  • 初始发行

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

plone.directives.dexterity-1.0.2.zip (25.5 kB 查看哈希

已上传 source