2

在一个香草 Plone 4.3.3 站点(Ubuntu 14.04.1LTS 上的统一安装程序)上,在使用 zopeskel 和 paste 样板文件更新 buildout.cfg 并运行 buildout 之后,我成功地在我的 src 文件夹中创建了一个 dexterity 包:

$ cd src  
$ ../bin/zopeskel dexterity my.package

在更新 buildout.cfg(将 my.package 添加到 egg 部分并将 src/my.package 添加到 development 部分)并运行 buildout 后,我​​将内容添加到我的新包中:

$ cd my.package  
$ ../../bin/paster addcontent dexterity_content

我将新的内容类型称为 mytype,生成了 mytype.py、一个名为 mytype_templates 的模板文件夹等。

重新启动 Plone 和....到目前为止,很好....

然后我将模板添加到 mytype_templates 文件夹:

add.pt
edit.pt
view.pt

在 mytype.py 文件中,我添加了所有必要的导入、模式定义

Class Imytype(form.Schema, IImageScaleTraversable):
    ....
    ....

等,当然还有视图、添加和编辑类:

class View(dexterity.DisplayForm):
    grok.context(Imytype)
    grok.require('zope2.View')

    # Disable turn fieldsets to tabs behavior
    enable_form_tabbing  = False

    def update(self):
        super(View, self).update()


class Add(dexterity.AddForm):
    grok.name('my.package.mytype')

    # Disable turn fieldsets to tabs behavior
    enable_form_tabbing  = False

    def __init__(self, context, request):
        super(Add, self).__init__(context, request)
    ......
    ......

class Edit(dexterity.EditForm):
    grok.context(Imytype)

    # Disable turn fieldsets to tabs behavior
    enable_form_tabbing  = False

    def update(self):
        super(Edit, self).update()
    ......
    ......

当我以前台模式重新启动我的 Plone 站点时,我收到以下消息:

2015-02-06 12:52:41 INFO ZServer HTTP server started at Fri Feb  6 12:52:41 2015
Hostname: 0.0.0.0
Port: 8080
/home/Plone434_site/buildout-cache/eggs/grokcore.view-2.8-py2.7.egg/grokcore/view/templatereg.py:261: UserWarning: Found the following unassociated template after configuration: /home/Plone434_site/zinstance/src/my.package/my/package/mytype_templates/edit.pt
  warnings.warn(msg, UserWarning, 1)
/home/Plone434_site/buildout-cache/eggs/grokcore.view-2.8-py2.7.egg/grokcore/view/templatereg.py:261: UserWarning: Found the following unassociated template after configuration: /home/Plone434_site/zinstance/src/my.package/my/package/mytype_templates/add.pt
  warnings.warn(msg, UserWarning, 1)
2015-02-06 12:52:46 INFO Zope Ready to handle requests

貌似 grok 成功获取了 view.pt,而不是 add.pt 和 edit.pt
这通过自定义模板得到证实。对 view.pt 的更改呈现正常,对 add.pt 和 edit.pt 的更改没有结果。Plone 使用默认的灵巧模板,因为 add.pt 和 edit.pt 没有被理解。

我通过添加以下内容找到了解决方法:

....
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
....

并添加到类:

    template = ViewPageTemplateFile('mytype_templates/add.pt')

和编辑类:

    template = ViewPageTemplateFile('mytype_templates/edit.pt')

显然上面列出的错误消息仍然存在,但至少它可以工作,我可以自定义 add.pt 和 edit.pt。虽然我可以接受这种解决方法,但我想知道为什么只有 view.pt 被破解,而不是 add.pt 和 edit.pt。请注意,使用 Plone 4.3.1、4.3.2、4.3.3 和 4.3.4 也复制了这种(奇怪的?)行为

有什么建议么?

4

1 回答 1

1

您必须声明视图的namecontextlayerschema使用这样的东西(注意grok.layer可能你缺少的方法):

class AddForm(dexterity.AddForm):
    grok.name('my.package.mytype')
    grok.layer(Imylayer)
    grok.context(Imytype)
    schema = Imytype

    def update(self):
        super(AddForm, self).update()
        ...


class EditForm(dexterity.EditForm):
    grok.context(Imytype)
    grok.layer(Imylayer)
    schema = Imytype

    def update(self):
        super(EditForm, self).update()
        ...

或者,您可以完全跳过 Grok 的使用,并通过 ZCML 注册所有内容。

在collective.nitf包中可以找到一个例子。有一个使用 Grok 的分支一个删除它的拉取请求

于 2015-02-25T16:38:18.390 回答