我已经创建了自定义内容类型(简历),我希望提供自定义的“编辑”视图。我的用例非常简单,我只想在编辑表单之前显示HTML“免责声明”框。Plone 4中的自定义编辑视图
首先我抄:
Products/ATContentTypes/skins/ATContentTypes/atct_edit.cpt
Products/ATContentTypes/skins/ATContentTypes/atct_edit.cpt.metadata
到我/产品/浏览/作为
my/product/browser/resumeedit.cpt
my/product/browser/resumeedit.cpt.metadata
然后我定义了一个新的浏览器:页面节在我/产品/browser/configure.zcml:
<browser:page
for="..interfaces.IResume"
name="resume_edit"
class=".resumeview.ResumeEdit"
template="resumeedit.cpt"
permission="cmf.ModifyPortalContent"
/>
在简历类我/产品/浏览/ resumeview.py很简单:
class ResumeEdit(BrowserView):
""" A customization of the Resume Edit form
"""
__call__ = ViewPageTemplateFile('resumeedit.cpt')
最后,我在改变了“编辑”默认别名我/产品/型材/默认/类型/ resume.xml中:
<alias from="edit" to="resume_edit" />
安装时,添加或编辑简历内容类型抛出此异常:
Unauthorized: The container has no security assertions. Access to 'id' of (Products.Five.browser.pagetemplatefile.ViewPageTemplateFile object at 0x1e8b7a50) denied.
这是通过提供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())"
然而,这引起了以下异常( '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'
我该如何解决这个问题,并为我的内容类型的编辑视图提供自己的自定义模板?
请注意'cpt'是一个FormController模板,只是复制它在Zope3视图中用作常规页面模板可能会导致各种问题。 '.metadata'文件仅在皮肤层上下文中有意义,并且完全被浏览器视图忽略。 – 2011-05-04 18:53:42
感谢您解决这个问题。 – zedr 2011-05-05 08:26:36
有关定制编辑模板的其他一些有价值的信息:http://www.llakomy.com/articles/new-submit-button-for-archetypes-edit-template – zedr 2011-05-05 08:51:30