Moving Dexerity fields to different schema?

We have a Dexterity behavior with lots of fields placed in its own schemata.
We need to place the title + description on top of the same schema instead within the default schemata.

Is there any straight-forward (and clean) way.

Andreas

References

https://groups.google.com/forum/#!topic/dexterity-development/kx-zH9O34TI


It can be done with Diazo:

    <before css:content-children="#fieldset-YOURSCHEMATA">
       <include css:content="#formfield-form-widgets-title" />
       <include css:content="#formfield-form-widgets-description" />
    </before>

There should be another way, doing it with Diazo doesn't feel right.
IIRC, there is no easy way to move fields between schematas.
But a field from your own schema can be moved to another fieldset with plone.supermodel.model.fieldset. See: https://github.com/plone/plone.app.event/blob/1.2.x/plone/app/event/dx/behaviors.py#L70
That would mean that you have to make a derivated dublin core behavior with your own title and description...

fieldset() works only for me own schemata but I can not move a different field into my schemata...well...customer needs to click on the default tab...little motivation for making this customer request happen.

Andreas

Idea (untested and off head):

You may be able to move it by manipulating the tagged values on the behavior directly.

from plone.app.dexterity.behaviors.metadata import IDublinCore
from plone.supermodel.interfaces import FIELDSETS_KEY
from plone.supermodel.model import Fieldset

custom_fieldset = Fieldset(
    'mycustomset',
    label=_(u'My Custom Set'), 
    fields=['title', 'description']
)
fieldsets = IDublinCore.getTaggedValue(FIELDSETS_KEY)
# TODO: if title and description are in a fieldset you may need to remove them there.
fieldsets.append(custom_fieldset)
# here I'am not sure if this is needed:
IDublinCore.setTaggedValue(FIELDSETS_KEY, current)

Please tell me if this works.

Poking around to try moving IVersionable.changeNote to another (non-Default) fieldset...

What is current here?

current is not needed. I had the same usecase now and this is how I could solve it (moving changeNote to the settings fieldset):

from plone.app.dexterity import _ as _DX
from plone.app.versioningbehavior.behaviors import IVersionable
from plone.supermodel.interfaces import FIELDSETS_KEY
from plone.supermodel.model import Fieldset


settings = Fieldset(
    'settings',
    label=_DX(u'Settings'),
    fields=['changeNote'],
)
fieldsets = IVersionable.getTaggedValue(FIELDSETS_KEY)
fieldsets.append(settings)
2 Likes

This works for me

from plone.dexterity.browser import edit
from plone.z3cform.fieldsets.utils import move

class EditForm(edit.DefaultEditForm):

    def updateFields(self):
        """ Remove field and group from versioningbehavior """
        super(EditForm, self).updateFields()
        move(self, 'IVersionable.changeNote', before='IVersionable.versioning_enabled')

with ZCML of:

  <browser:page
      for="scuk.contenttypes.content.chaplains_visit.IChaplainsVisit"
      name="edit"
      class=".chaplains_visit_views.EditForm"
      permission="cmf.ModifyPortalContent"
      />

You'ld need to repeat it for Add and Display views too of course, but it's clean and it might help some situations.

1 Like