Migrating Edit Views

Hi,

I'm having some troubles trying to create a custom edit view for my content type. I am currently doing a Migration, and in my previous version of the content type I had a skins folder with that "custom edit" for the content type (and also some skins that were related to the widgets that I don't quite understand what it was doing, but I think it was needed for then using, on browser folder views, for example: <metal:field use-macro="python:here.widget(field.getName(), mode='view')">Main text</metal:field>). So, what I was looking help for was on creating this edit custom view, because, I've tried to base on edit.py from plone.dexterity but I am confused on how to manipulate how the fields appear and what fields I really want to display. Also, if you could give some help on the widget skins I was talking about I would love the help on how to "imitate" the previous views I had ahah. Thank you so much!

I recommended reading

In short:

  • your Python code of the view class should use DefaultView instead of BrowserView
  • there is example code above to render widgets

Also check this:

in particular this coding pattern inside a view:

<div tal:replace="structure view/w/IShortName.id/ploneform-render-widget" />
```
1 Like

I think it will be something like this

  1. in your add-on, in browser/configure.zcml add something like this:

    <browser:page
    name="edit"
    for="Some.Interface"
    class=".views.MyContentTypeEditFormView"
    permission="cmf.ModifyPortalContent"
    layer="my.addon.interfaces.IMyAddonLayer"
    />

Then, in the view something like this (maybe you dont need all the lines)

from zope.publisher.browser import BrowserView
#from plone.dexterity.browser.add import DefaultAddView
#from plone.dexterity.browser.add import DefaultAddForm
from plone.dexterity.browser.edit import DefaultEditView
from plone.dexterity.browser.edit import DefaultEditForm
from plone.dexterity.browser import edit
#from plone.uuid.interfaces import IUUID
from zope.intid.interfaces import IIntIds
from Products.CMFCore.utils import getToolByName
#from z3c.relationfield import RelationValue
#from plone import api
from zope.component import getUtility
from z3c.form import interfaces
from plone.app.versioningbehavior.behaviors import IVersionable
#from z3c.form.browser.text import TextWidget
from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile as Z3ViewPageTemplateFile



class MyContentTypenEditForm(DefaultEditForm):
    portal_type = "my_content_type"
    default_fieldset_label = 'Some Label here'

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

    def updateWidgets(self):
        super(MyContentTypenEditForm, self).updateWidgets()
        self.widgets['IDublinCore.title'].label = 'Another title' 

    def updateFields(self):
        super(MyContentTypenEditForm, self).updateFields()


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

        if self.portal_type =='my_content_type':
            for group in self.groups:
                if group.__name__ == 'settings':
                    #group.mode = 'omitted'
                    group.label = None
                    group.widgets['IVersionable.versioning_enabled'].mode = interfaces.HIDDEN_MODE



class MyContentTypenEditFormView(DefaultEditView):
    portal_type = "my_contentype"
    default_fieldset_label = 'Default Something'
    form = MyContentTypenEditForm

NOTE: A content type often has 'extra' views for 1) add view 2) edit view. You might need to make all if you have speicial requirements.

Just to be sure: You are talking about the view which URI ends with /@edit

1 Like

Besides what @zopyx said, you can also have a look at new docs, currently in review.
You can find the preview here, until they are merged into the public docs.

or the form chapter, where you can find example code how to override a edit/add view.

And the general chapter about views:

1 Like