Plone 4中的自定义编辑视图

Rig*_*ala 4 content-type plone edit view archetypes

我创建了一个自定义内容类型(简历),我希望提供一个自定义的"编辑"视图.我的用例非常简单,我只想在编辑表单之前显示一个HTML"免责声明"框.

首先我复制了:

Products/ATContentTypes/skins/ATContentTypes/atct_edit.cpt
Products/ATContentTypes/skins/ATContentTypes/atct_edit.cpt.metadata
Run Code Online (Sandbox Code Playgroud)

进入我的/ product/browser / as

my/product/browser/resumeedit.cpt
my/product/browser/resumeedit.cpt.metadata
Run Code Online (Sandbox Code Playgroud)

然后我定义了一个新的浏览器:my/product/browser/configure.zcml中的页面节:

  <browser:page
   for="..interfaces.IResume"
   name="resume_edit"
   class=".resumeview.ResumeEdit"
   template="resumeedit.cpt"
   permission="cmf.ModifyPortalContent"
   />
Run Code Online (Sandbox Code Playgroud)

我的/ product/browser/resumeview.py中的resume类只是:

class ResumeEdit(BrowserView):
""" A customization of the Resume Edit form
"""
    __call__  = ViewPageTemplateFile('resumeedit.cpt')
Run Code Online (Sandbox Code Playgroud)

最后,我在/ product/profiles/default/types/Resume.xml中更改了'edit'的默认别名:

  <alias from="edit" to="resume_edit" />
Run Code Online (Sandbox Code Playgroud)

安装后,添加或编辑Resume内容类型会引发此异常:

Unauthorized: The container has no security assertions.  Access to 'id' of (Products.Five.browser.pagetemplatefile.ViewPageTemplateFile object at 0x1e8b7a50) denied.
Run Code Online (Sandbox Code Playgroud)

通过提供修补版本的edit_macros.pt可以减轻这种情况:

85c85
<             tal:attributes="action python:context.absolute_url()+'/'+template.id;
---
>             tal:attributes="action python:context.absolute_url()+'/'+path('template/getId|nothing');
203c203
<                    tal:attributes="value python:(last_referer and '%s/%s' % (context.absolute_url(), template.id) not in last_referer) and last_referer or (context.getParentNode() and context.getParentNode().absolute_url())"
---
>                    tal:attributes="value python:(last_referer and '%s/%s' % (context.absolute_url(), path('template/getId|nothing')) not in last_referer) and last_referer or (context.getParentNode() and context.getParentNode().absolute_url())"
Run Code Online (Sandbox Code Playgroud)

仍然,这引发了以下异常('id-64121786'是我的简历项的id):

  Module zope.tales.tales, line 696, in evaluate
   - URL: file:/home/zope/env26/plone-devel/eggs/Products.Archetypes-1.6.5-py2.6.egg/Products/Archetypes/skins/archetypes/widgets/field.pt
   - Line 63, Column 4
   - Expression: <PythonExpr errors.get(fieldName)>
   - Names:
      {'args': (),
       'container': <Resume at /cms/id-64121786>,
       'context': <Resume at /cms/id-64121786>,
       'default': <object object at 0x8e094c0>,
       'here': <Resume at /cms/id-64121786>,
       'loop': {},
       'nothing': None,
       'options': {},
       'repeat': <Products.PageTemplates.Expressions.SafeMapping object at 0x126e7470>,
       'request': <HTTPRequest, URL=http://localhost:8081/cms/id-64121786/resume_edit>,
       'root': <Application at >,
       'template': <Products.Five.browser.pagetemplatefile.ViewPageTemplateFile object at 0x117da910>,
       'traverse_subpath': [],
       'user': <PloneUser 'admin'>,
       'view': <Products.Five.metaclass.SimpleViewClass from /home/zope/env26/plone-devel/src/my.product/my/product/browser/resumeedit.cpt object at 0x126d8c90>,
       'views': <Products.Five.browser.pagetemplatefile.ViewMapper object at 0x126d8fd0>}
  Module Products.PageTemplates.ZRPythonExpr, line 49, in __call__
   - __traceback_info__: errors.get(fieldName)
  Module PythonExpr, line 1, in <expression>
  Module AccessControl.ImplPython, line 688, in guarded_getattr
AttributeError: 'NoneType' object has no attribute 'get'
Run Code Online (Sandbox Code Playgroud)

如何解决此问题并为我的内容类型的编辑视图提供我自己的自定义模板?

acl*_*ark 6

我建议不要复制atct_edit.cpt.您真正需要做的就是配置一个编辑模板(看起来你知道该怎么做),然后覆盖相应的部分.请参阅此处的文档以获取更多信

另外,我先从一个完全空白的编辑模板开始.然后在其中放入一些有效的XHTML,例如<span> Hello world!</ span>并确保您可以通过单击编辑按钮来加载编辑模板.

  • 你似乎不理解Martijn在上面提出的观点.atct_edit不是Zope3浏览器视图.将模板放在皮肤/模板目录中,名为**resume_edit.pt**.不需要zcml.它不太理想,但我认为我们必须等待Archetypes的死亡才能使用真实的视图(如果编辑模板是浏览器视图,那么只需向视图添加一个Viewlet就可以轻松完成所需的操作) (6认同)
  • 这两个错误都是不言自明的."没有安全断言"意味着您正在尝试访问您没有权限的对象(粗略地).而"属性错误"意味着您正在向对象询问它没有的属性.(在这种情况下,没有对象,即Nonetype,因此它没有属性.) (3认同)
  • 谢谢Auspex.我通过在*skins/templates*中复制base_edit.cpt和base_edit.cpt.metadata(并重命名它们)解决了这个问题,从而解决了错误"AttributeError:'NoneType'对象没有属性'get'" (2认同)