Custom Editing Types in Plone 4

I created a custom content type (Resume), and I want to provide a custom "edit" view. My use case is very simple, I just want to show the β€œopt-out” HTML window before the edit form.

First of all, I copied:

Products/ATContentTypes/skins/ATContentTypes/atct_edit.cpt Products/ATContentTypes/skins/ATContentTypes/atct_edit.cpt.metadata 

in my / product / browser / like

 my/product/browser/resumeedit.cpt my/product/browser/resumeedit.cpt.metadata 

Then I defined a new browser: stanza pages in my / product / browser / configure.zcml :

  <browser:page for="..interfaces.IResume" name="resume_edit" class=".resumeview.ResumeEdit" template="resumeedit.cpt" permission="cmf.ModifyPortalContent" /> 

The resume class in my / product / browser / resumeview.py looks simple:

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

Finally, I changed the default alias for 'edit' to my / product / profiles / default / types / Resume.xml :

  <alias from="edit" to="resume_edit" /> 

During installation, adding or editing a resume content type causes this exception:

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

This is mitigated by providing a revised version of 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())" 

However, this throws the following exception ('id-64121786' is the identifier of my resume element):

  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' 

How can I solve this problem and provide my own custom template for editing the look of my content?

+4
source share
3 answers

I would suggest not copying atct_edit.cpt. All you really need to do is set up an editing template (which looks like you know how to do it) and then override the relevant parts. See the documentation here for more information.

Also, first, I'll start with a completely empty editing template. Then add some valid XHTML to it, for example. <span> Hello world! </span> and make sure you can download the editing template by clicking the edit button.

+6
source

To answer alex's answer: an alternative solution can also provide your own editing form via z3c.form / plone.autoform, if you do not mind additional dependencies. See this guide for a basic introduction / idea.

+3
source

For this you must use the widget.

Register a viewport for each view, make a specific check of the display of what you want.

So you do not need to recreate the form

+3
source

All Articles