From 2cfe976d2dd1e05d058a4d59b0ea979d0453efcc Mon Sep 17 00:00:00 2001 From: Dylan Jay Date: Sat, 17 Sep 2016 01:32:24 +0700 Subject: [PATCH] merge field schema into one tab --- src/Products/CMFPlomino/contents/field.py | 69 ++++++++++--------- src/Products/CMFPlomino/fields/attachment.py | 14 ++-- src/Products/CMFPlomino/fields/boolean.py | 13 ++-- src/Products/CMFPlomino/fields/datagrid.py | 20 +++--- src/Products/CMFPlomino/fields/datetime.py | 16 +++-- src/Products/CMFPlomino/fields/doclink.py | 23 +++---- src/Products/CMFPlomino/fields/googlechart.py | 12 ++-- .../CMFPlomino/fields/googlevisualization.py | 15 ++-- src/Products/CMFPlomino/fields/name.py | 17 +++-- src/Products/CMFPlomino/fields/number.py | 18 +++-- src/Products/CMFPlomino/fields/richtext.py | 12 ++-- src/Products/CMFPlomino/fields/selection.py | 30 +++++--- src/Products/CMFPlomino/fields/text.py | 20 ++++-- 13 files changed, 149 insertions(+), 130 deletions(-) diff --git a/src/Products/CMFPlomino/contents/field.py b/src/Products/CMFPlomino/contents/field.py index 60f846a41..1086fab72 100644 --- a/src/Products/CMFPlomino/contents/field.py +++ b/src/Products/CMFPlomino/contents/field.py @@ -81,6 +81,7 @@ class IPlominoField(model.Schema): """ Plomino field schema """ + #directives.widget('field_type', onchange=u'this.form.submit()') field_type = schema.Choice( title=_('CMFPlomino_label_FieldType', default="Field type"), description=_('CMFPlomino_label_FieldType', default="Field type"), @@ -89,6 +90,24 @@ class IPlominoField(model.Schema): vocabulary=field_types, ) + mandatory = schema.Bool( + title=_('CMFPlomino_label_FieldMandatory', default="Mandatory"), + description=_('CMFPlomino_help_FieldMandatory', + default='Is this field mandatory? (empty value will not be ' + 'allowed)'), + default=False, + required=True, + ) + + directives.widget('validation_formula', klass='plomino-formula') + validation_formula = schema.Text( + title=_('CMFPlomino_label_FieldValidation', + default="Validation formula"), + description=_('CMFPlomino_help_FieldValidation', + default='Evaluate the input validation'), + required=False, + ) + field_mode = schema.Choice( title=_('CMFPlomino_label_FieldMode', default="Field mode"), description=_('CMFPlomino_label_FieldMode', default="Field mode"), @@ -115,40 +134,6 @@ class IPlominoField(model.Schema): required=False, ) - read_template = schema.TextLine( - title=_('CMFPlomino_label_FieldReadTemplate', - default="Field read template"), - description=_('CMFPlomino_help_FieldReadTemplate', - default='Custom rendering template in read mode'), - required=False, - ) - - edit_template = schema.TextLine( - title=_('CMFPlomino_label_FieldEditTemplate', - default="Field edit template"), - description=_('CMFPlomino_help_FieldEditTemplate', - default='Custom rendering template in edit mode'), - required=False, - ) - - mandatory = schema.Bool( - title=_('CMFPlomino_label_FieldMandatory', default="Mandatory"), - description=_('CMFPlomino_help_FieldMandatory', - default='Is this field mandatory? (empty value will not be ' - 'allowed)'), - default=False, - required=True, - ) - - directives.widget('validation_formula', klass='plomino-formula') - validation_formula = schema.Text( - title=_('CMFPlomino_label_FieldValidation', - default="Validation formula"), - description=_('CMFPlomino_help_FieldValidation', - default='Evaluate the input validation'), - required=False, - ) - to_be_indexed = schema.Bool( title=_('CMFPlomino_label_FieldIndex', default="Add to index"), description=_('CMFPlomino_help_FieldIndex', @@ -175,6 +160,22 @@ class IPlominoField(model.Schema): required=False, ) + read_template = schema.TextLine( + title=_('CMFPlomino_label_FieldReadTemplate', + default="Field read template"), + description=_('CMFPlomino_help_FieldReadTemplate', + default='Custom rendering template in read mode'), + required=False, + ) + + edit_template = schema.TextLine( + title=_('CMFPlomino_label_FieldEditTemplate', + default="Field edit template"), + description=_('CMFPlomino_help_FieldEditTemplate', + default='Custom rendering template in edit mode'), + required=False, + ) + class PlominoField(Item): implements(IPlominoField, IInstanceBehaviorAssignableContent) diff --git a/src/Products/CMFPlomino/fields/attachment.py b/src/Products/CMFPlomino/fields/attachment.py index 23ad91e0a..7bdd91409 100644 --- a/src/Products/CMFPlomino/fields/attachment.py +++ b/src/Products/CMFPlomino/fields/attachment.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from plone.autoform.interfaces import IFormFieldProvider +from plone.autoform.interfaces import IFormFieldProvider, ORDER_KEY from plone.supermodel import directives, model from Products.CMFPlone.utils import normalizeString from zope.interface import implementer, provider @@ -17,12 +17,6 @@ class IAttachmentField(model.Schema): """ Attachment field schema """ - directives.fieldset( - 'settings', - label=_(u'Settings'), - fields=('single_or_multiple', ), - ) - single_or_multiple = schema.Choice( vocabulary=SimpleVocabulary.fromItems( [("Single file", "SINGLE"), ("Multiple files", "MULTI")]), @@ -31,6 +25,12 @@ class IAttachmentField(model.Schema): default="MULTI", required=True) +# bug in plone.autoform means order_after doesn't moves correctly +IAttachmentField.setTaggedValue(ORDER_KEY, + [('single_or_multiple', 'after', 'field_type'), + ] +) + @implementer(IAttachmentField) class AttachmentField(BaseField): diff --git a/src/Products/CMFPlomino/fields/boolean.py b/src/Products/CMFPlomino/fields/boolean.py index 90e042857..5cbc703dd 100644 --- a/src/Products/CMFPlomino/fields/boolean.py +++ b/src/Products/CMFPlomino/fields/boolean.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from plone.autoform.interfaces import IFormFieldProvider +from plone.autoform.interfaces import IFormFieldProvider, ORDER_KEY from plone.supermodel import directives, model from zope.interface import implementer, provider from zope.pagetemplate.pagetemplatefile import PageTemplateFile @@ -16,12 +16,6 @@ class IBooleanField(model.Schema): """ """ - directives.fieldset( - 'settings', - label=_(u'Settings'), - fields=('widget', ), - ) - widget = schema.Choice( vocabulary=SimpleVocabulary.fromItems([ ("Single checkbox", "CHECKBOX") @@ -31,6 +25,11 @@ class IBooleanField(model.Schema): default="CHECKBOX", required=True) +# bug in plone.autoform means order_after doesn't moves correctly +IBooleanField.setTaggedValue(ORDER_KEY, + [('widget', 'after', 'field_type'), + ] +) @implementer(IBooleanField) class BooleanField(BaseField): diff --git a/src/Products/CMFPlomino/fields/datagrid.py b/src/Products/CMFPlomino/fields/datagrid.py index d954bc889..10307efba 100644 --- a/src/Products/CMFPlomino/fields/datagrid.py +++ b/src/Products/CMFPlomino/fields/datagrid.py @@ -2,7 +2,7 @@ from jsonutil import jsonutil as json from DateTime import DateTime -from plone.autoform.interfaces import IFormFieldProvider +from plone.autoform.interfaces import IFormFieldProvider, ORDER_KEY from plone.supermodel import directives, model from zope.interface import implementer, provider from zope.pagetemplate.pagetemplatefile import PageTemplateFile @@ -20,16 +20,6 @@ class IDatagridField(model.Schema): """ Datagrid field schema """ - directives.fieldset( - 'settings', - label=_(u'Settings'), - fields=( - 'widget', - 'associated_form', - 'field_mapping', - ), - ) - widget = schema.Choice( vocabulary=SimpleVocabulary.fromItems([ ("Always dynamic", "REGULAR"), @@ -51,6 +41,14 @@ class IDatagridField(model.Schema): description=u'Field ids from the associated form, separated by commas.', required=False) +# bug in plone.autoform means order_after doesn't moves correctly +IDatagridField.setTaggedValue(ORDER_KEY, + [('widget', 'after', 'field_type'), + ('associated_form', 'after', ".widget"), + ('field_mapping', 'after', ".associated_form"), + ] +) + @implementer(IDatagridField) class DatagridField(BaseField): diff --git a/src/Products/CMFPlomino/fields/datetime.py b/src/Products/CMFPlomino/fields/datetime.py index 8f521523e..14ac1d025 100644 --- a/src/Products/CMFPlomino/fields/datetime.py +++ b/src/Products/CMFPlomino/fields/datetime.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from DateTime import DateTime -from plone.autoform.interfaces import IFormFieldProvider +from plone.autoform.interfaces import IFormFieldProvider, ORDER_KEY from plone.supermodel import directives, model from zope.interface import implementer, provider from zope.pagetemplate.pagetemplatefile import PageTemplateFile @@ -18,12 +18,6 @@ class IDatetimeField(model.Schema): """ DateTime field schema """ - directives.fieldset( - 'settings', - label=_(u'Settings'), - fields=('widget', 'format', 'startingyear'), - ) - widget = schema.Choice( vocabulary=SimpleVocabulary.fromItems([ ("Default", "SERVER"), @@ -45,6 +39,14 @@ class IDatetimeField(model.Schema): description=u"Oldest year selectable in the calendar widget", required=False) +# bug in plone.autoform means order_after doesn't moves correctly +IDatetimeField.setTaggedValue(ORDER_KEY, + [('widget', 'after', 'field_type'), + ('format', 'after', ".widget"), + ('startingyear', 'after', ".format"), + ] +) + @implementer(IDatetimeField) class DatetimeField(BaseField): diff --git a/src/Products/CMFPlomino/fields/doclink.py b/src/Products/CMFPlomino/fields/doclink.py index 5abcebe66..beb14087f 100644 --- a/src/Products/CMFPlomino/fields/doclink.py +++ b/src/Products/CMFPlomino/fields/doclink.py @@ -2,7 +2,7 @@ from jsonutil import jsonutil as json from plone.autoform import directives as form -from plone.autoform.interfaces import IFormFieldProvider +from plone.autoform.interfaces import IFormFieldProvider, ORDER_KEY from plone.supermodel import directives, model from zope.interface import implementer, provider from zope.pagetemplate.pagetemplatefile import PageTemplateFile @@ -21,18 +21,6 @@ class IDoclinkField(model.Schema): """ Selection field schema """ - directives.fieldset( - 'settings', - label=_(u'Settings'), - fields=( - 'widget', - 'sourceview', - 'labelcolumn', - 'documentslistformula', - 'separator', - ), - ) - widget = schema.Choice( vocabulary=SimpleVocabulary.fromItems([ ("Selection list", "SELECT"), @@ -67,6 +55,15 @@ class IDoclinkField(model.Schema): description=u'Only apply if multiple values will be displayed', required=False) +# bug in plone.autoform means order_after doesn't moves correctly +IDoclinkField.setTaggedValue(ORDER_KEY, + [('widget', 'after', 'field_type'), + ('sourceview', 'after', ".widget"), + ('labelcolumn', 'after', ".sourceview"), + ('documentslistformula', 'after', ".labelcolumn"), + ('separator', 'after', ".documentslistformula"), + ] +) @implementer(IDoclinkField) class DoclinkField(BaseField): diff --git a/src/Products/CMFPlomino/fields/googlechart.py b/src/Products/CMFPlomino/fields/googlechart.py index edc76dd76..c479eef8b 100644 --- a/src/Products/CMFPlomino/fields/googlechart.py +++ b/src/Products/CMFPlomino/fields/googlechart.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from plone.autoform.interfaces import IFormFieldProvider +from plone.autoform.interfaces import IFormFieldProvider, ORDER_KEY from plone.supermodel import directives, model from zope.interface import implementer, provider from zope.pagetemplate.pagetemplatefile import PageTemplateFile @@ -16,11 +16,6 @@ class IGooglechartField(model.Schema): """ Google chart field schema """ - directives.fieldset( - 'settings', - label=_(u'Settings'), - fields=('editrows', ), - ) editrows = schema.TextLine( title=u'Rows', @@ -28,6 +23,11 @@ class IGooglechartField(model.Schema): default=u"6", required=False) +# bug in plone.autoform means order_after doesn't moves correctly +IGooglechartField.setTaggedValue(ORDER_KEY, + [('editrows', 'after', 'field_type'), + ] +) @implementer(IGooglechartField) class GooglechartField(BaseField): diff --git a/src/Products/CMFPlomino/fields/googlevisualization.py b/src/Products/CMFPlomino/fields/googlevisualization.py index bf40b8970..13fb3ef5a 100644 --- a/src/Products/CMFPlomino/fields/googlevisualization.py +++ b/src/Products/CMFPlomino/fields/googlevisualization.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from plone.autoform.interfaces import IFormFieldProvider +from plone.autoform.interfaces import IFormFieldProvider, ORDER_KEY from plone.autoform import directives as form from plone.supermodel import directives, model from zope.interface import implementer, provider @@ -29,12 +29,6 @@ class IGooglevisualizationField(model.Schema): """ Google viz field schema """ - directives.fieldset( - 'settings', - label=_(u'Settings'), - fields=('jssettings', 'chartid', ), - ) - form.widget('jssettings', klass='plomino-formula') jssettings = schema.Text( title=u'Javascript settings', @@ -76,6 +70,13 @@ class IGooglevisualizationField(model.Schema): required=True, default=u'gvisudata') +# bug in plone.autoform means order_after doesn't moves correctly +IGooglevisualizationField.setTaggedValue(ORDER_KEY, + [('jssettings', 'after', 'field_type'), + ('chartid', 'after', ".jssettings"), + ] +) + @implementer(IGooglevisualizationField) class GooglevisualizationField(BaseField): diff --git a/src/Products/CMFPlomino/fields/name.py b/src/Products/CMFPlomino/fields/name.py index ec5900485..9a2f91442 100644 --- a/src/Products/CMFPlomino/fields/name.py +++ b/src/Products/CMFPlomino/fields/name.py @@ -2,7 +2,7 @@ from jsonutil import jsonutil as json from plone import api -from plone.autoform.interfaces import IFormFieldProvider +from plone.autoform.interfaces import IFormFieldProvider, ORDER_KEY from plone.supermodel import directives, model from zope.interface import implementer, provider from zope.pagetemplate.pagetemplatefile import PageTemplateFile @@ -18,12 +18,6 @@ class INameField(model.Schema): """ Name field schema """ - directives.fieldset( - 'settings', - label=_(u'Settings'), - fields=('type', 'selector', 'restricttogroup', 'separator', ), - ) - type = schema.Choice( vocabulary=SimpleVocabulary.fromItems([ ("Single valued", "SINGLE"), @@ -55,6 +49,15 @@ class INameField(model.Schema): description=u'Only apply if multiple values will be displayed', required=False) +# bug in plone.autoform means order_after doesn't moves correctly +INameField.setTaggedValue(ORDER_KEY, + [('type', 'after', 'field_type'), + ('selector', 'after', ".type"), + ('restricttogroup', 'after', ".selector"), + ('separator', 'after', ".restricttogroup"), + ] +) + @implementer(INameField) class NameField(BaseField): diff --git a/src/Products/CMFPlomino/fields/number.py b/src/Products/CMFPlomino/fields/number.py index 54d465395..97d07c4e9 100644 --- a/src/Products/CMFPlomino/fields/number.py +++ b/src/Products/CMFPlomino/fields/number.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from decimal import Decimal -from plone.autoform.interfaces import IFormFieldProvider +from plone.autoform.interfaces import IFormFieldProvider, ORDER_KEY from plone.supermodel import directives, model from zope.interface import implementer, provider from zope.pagetemplate.pagetemplatefile import PageTemplateFile @@ -18,11 +18,11 @@ class INumberField(model.Schema): """ Number field schema """ - directives.fieldset( - 'settings', - label=_(u'Settings'), - fields=('number_type', 'size', 'format', ), - ) + # directives.fieldset( + # 'settings', + # label=_(u'Settings'), + # fields=('number_type', 'size', 'format', ), + # ) number_type = schema.Choice( vocabulary=SimpleVocabulary.fromItems([ @@ -44,6 +44,12 @@ class INumberField(model.Schema): title=u'Format', description=u'Number formatting (example: %1.2f)', required=False) +# bug in plone.autoform means order_after doesn't moves correctly +INumberField.setTaggedValue(ORDER_KEY, + [('number_type', 'after', 'field_type'), + ('size', 'after', ".number_type"), + ('format', 'after', ".size")] +) @implementer(INumberField) diff --git a/src/Products/CMFPlomino/fields/richtext.py b/src/Products/CMFPlomino/fields/richtext.py index e8f7e5705..8d4419fbb 100644 --- a/src/Products/CMFPlomino/fields/richtext.py +++ b/src/Products/CMFPlomino/fields/richtext.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from plone.autoform.interfaces import IFormFieldProvider +from plone.autoform.interfaces import IFormFieldProvider, ORDER_KEY from plone.supermodel import directives, model from zope.interface import implementer, provider from zope.pagetemplate.pagetemplatefile import PageTemplateFile @@ -15,17 +15,15 @@ class IRichtextField(model.Schema): """ Rich text field schema """ - directives.fieldset( - 'settings', - label=_(u'Settings'), - fields=('height', ), - ) - height = schema.TextLine( title=u'Height', description=u'Height in pixels', required=False) +# bug in plone.autoform means order_after doesn't moves correctly +IRichtextField.setTaggedValue(ORDER_KEY, + [('height', 'after', 'field_type')] +) @implementer(IRichtextField) class RichtextField(BaseField): diff --git a/src/Products/CMFPlomino/fields/selection.py b/src/Products/CMFPlomino/fields/selection.py index 528922efd..fdd18fb7f 100644 --- a/src/Products/CMFPlomino/fields/selection.py +++ b/src/Products/CMFPlomino/fields/selection.py @@ -2,7 +2,7 @@ from jsonutil import jsonutil as json from plone.autoform import directives as form -from plone.autoform.interfaces import IFormFieldProvider +from plone.autoform.interfaces import IFormFieldProvider, ORDER_KEY from plone.supermodel import directives, model from zope.interface import implementer, provider from zope.pagetemplate.pagetemplatefile import PageTemplateFile @@ -21,16 +21,16 @@ class ISelectionField(model.Schema): """ Selection field schema """ - directives.fieldset( - 'settings', - label=_(u'Settings'), - fields=( - 'widget', - 'selectionlist', - 'selectionlistformula', - 'separator', - ), - ) + # directives.fieldset( + # 'settings', + # label=_(u'Settings'), + # fields=( + # 'widget', + # 'selectionlist', + # 'selectionlistformula', + # 'separator', + # ), + # ) widget = schema.Choice( vocabulary=SimpleVocabulary.fromItems([ @@ -63,6 +63,14 @@ class ISelectionField(model.Schema): description=u'Only apply if multiple values will be displayed', required=False) +# bug in plone.autoform means order_after doesn't moves correctly +ISelectionField.setTaggedValue(ORDER_KEY, + [('widget', 'after', 'field_type'), + ('selectionlist', 'after', ".widget"), + ('selectionlistformula', 'after', ".selectionlist"), + ('separator', 'after', ".selectionlistformula")] +) + @implementer(ISelectionField) class SelectionField(BaseField): diff --git a/src/Products/CMFPlomino/fields/text.py b/src/Products/CMFPlomino/fields/text.py index 0419349bd..7d1df6a55 100644 --- a/src/Products/CMFPlomino/fields/text.py +++ b/src/Products/CMFPlomino/fields/text.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from plone.autoform.interfaces import IFormFieldProvider +from plone.autoform.interfaces import IFormFieldProvider, ORDER_KEY from plone.supermodel import directives, model from zope.interface import implementer, provider from zope.pagetemplate.pagetemplatefile import PageTemplateFile @@ -15,12 +15,12 @@ class ITextField(model.Schema): """ """ - - directives.fieldset( - 'settings', - label=_(u'Settings'), - fields=('widget', 'size', 'preserve_carriage_returns'), - ) + # + # directives.fieldset( + # 'settings', + # label=_(u'Settings'), + # fields=('widget', 'size', 'preserve_carriage_returns'), + # ) widget = schema.Choice( vocabulary=SimpleVocabulary.fromItems([ @@ -47,6 +47,12 @@ class ITextField(model.Schema): required=False, ) +# bug in plone.autoform means order_after doesn't moves correctly +ITextField.setTaggedValue(ORDER_KEY, + [('widget', 'after', 'field_type'), + ('size', 'after', ".widget"), + ('preserve_carriage_returns', 'after', ".size")] +) @implementer(ITextField) class TextField(BaseField):