2011-05-04 39 views
4

我已经创建了自定义内容类型(简历),我希望提供自定义的“编辑”视图。我的用例非常简单,我只想在编辑表单之前显示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' 

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

+4

请注意'cpt'是一个FormController模板,只是复制它在Zope3视图中用作常规页面模板可能会导致各种问题。 '.metadata'文件仅在皮肤层上下文中有意义,并且完全被浏览器视图忽略。 – 2011-05-04 18:53:42

+0

感谢您解决这个问题。 – zedr 2011-05-05 08:26:36

+1

有关定制编辑模板的其他一些有价值的信息:http://www.llakomy.com/articles/new-submit-button-for-archetypes-edit-template – zedr 2011-05-05 08:51:30

回答

6

我建议不要复制atct_edit.cpt。你真正需要做的是配置一个编辑模板(它看起来像你知道该怎么做),然后重写适当的部分。有关更多信息,请参见文档here

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

+0

谢谢。但是,使用您链接的页面中的模板并填充一些空白,我仍然会得到相同的错误。它似乎与以下TAL定义有关:* errors options/state/getErrors |没有; *在“主”宏。 – zedr 2011-05-04 15:36:26

+3

这两个错误都是不言自明的。 “没有安全声明”意味着你试图访问你没有权限的对象(大致)。而“属性错误”意味着你要求一个对象有一个它没有的属性。 (在这种情况下,没有任何对象,即Nonetype,因此它可以没有属性。) – aclark 2011-05-04 18:43:38

+6

您似乎并不理解Martijn在上面提出的观点。 atct_edit不是Zope3浏览器视图。将您的模板放在您的皮肤/模板目录中,名称为** resume_edit.pt **。不需要zcml。这并不理想,但我认为我们必须等待Archetypes的死亡才能使用真实的视图(如果编辑模板是Browser视图,只需将Viewlet添加到视图中即可完成所需内容) – Auspex 2011-05-04 19:41:06

3

要跟进alex的回答:如果您不反对额外的依赖关系,另一种解决方案也可以通过z3c.form/plone.autoform提供自己的编辑表单。有关基本介绍/想法,请参阅this manual

3

您必须使用一个viewlet来实现这一点。

为每个视图注册一个viewlet,对渲染调用进行一些检查,以显示每个你想要的。所以你不需要重新创建表格

相关问题