Had a similar usecase in the past. We used a custom edit form with a marker interface, and in the schema a configuration like this:
directives.omitted("product_group")
directives.no_omit(IAddForm, "product_group")
directives.no_omit(IAdminEditForm, "product_group")
product_group = schema.Choice(
description=_(
u"Please select the product group. "
u"Note that this selection can't be changed later."
),
required=True,
title=_(u"Product Group"),
vocabulary="my.product_groups",
)
If you want to show the fields, but not being able to edit them in the regular edit form (here we have a special admin edit form where admins with special permissions can edit the fields):
directives.mode(product_group="display")
directives.mode(IAddForm, product_group="input")
directives.mode(IAdminEditForm, product_group="input")
product_group = schema.Choice(
description=_(
u"Please select the product group. "
u"Note that this selection can't be changed later."
),
required=True,
title=_(u"Product Group"),
vocabulary="my.product_groups",
)
The custom admin edit form is derived from the default edit form:
class IAdminEditForm(IEditForm):
"""Custom edit form for admins."""
@implementer(IAdminEditForm)
class AdminEditForm(DefaultEditForm):
"""Custom edit form for admins."""
def update(self):
super(AdminEditForm, self).update()
if (
len(self.actions.executedActions) == 0
or self.status == self.formErrorsMessage
):
msg = _(u"You are currently editing this item in admin mode. Be careful!")
api.portal.show_message(message=msg, request=self.request, type="warning")
<!-- Custom edit form for admins. -->
<browser:page
class=".forms.AdminEditForm"
for="plone.dexterity.interfaces.IDexterityContent"
layer="my.custom.IMyLayer
name="admin-edit"
permission="cmf.ManagePortal"
/>
Maybe you dont need an edit form at all?
What about showing this 'bearbiten' button just for users with the right permissions (which you get from view/check_permissions" and then load a popup (form) that saves to the field (I think you can do this with one line of 'plone.api.content).
Yes I use collective.fieldedit for this use-case. It works in Plone 5.2 and Python 3 as well.
I'll fix the tests that fail in 5.2/py3 and make a release that officially supports these versions.
For some user cases, it could be useful if it was possible to make a 'Live Edit' (action) that enabled this on 'certain fields' (the fields the user has permissions on, probably)