src/pyams_form/interfaces/form.py
changeset 204 c435de184bda
parent 199 9167bef4d803
child 208 db681bb0380b
equal deleted inserted replaced
203:ba372884335f 204:c435de184bda
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
    10 # FOR A PARTICULAR PURPOSE.
    10 # FOR A PARTICULAR PURPOSE.
    11 #
    11 #
       
    12 
       
    13 """PyAMS_form.interfaces.form module
       
    14 
       
    15 This module provides all custom form-related interfaces.
       
    16 """
    12 
    17 
    13 from pyramid.interfaces import IView
    18 from pyramid.interfaces import IView
    14 from z3c.form import button
    19 from z3c.form import button
    15 from z3c.form.interfaces import IButtonWidget, IFormLayer as IBaseFormLayer, INPUT_MODE, \
    20 from z3c.form.interfaces import IButtonWidget, IFormLayer as IBaseFormLayer, INPUT_MODE, \
    16     ISelectWidget, ISubForm, ISubmitWidget, ITextAreaWidget, ITextWidget, IWidget
    21     ISelectWidget, ISubForm, ISubmitWidget, ITextAreaWidget, ITextWidget, IWidget
    26 from pyams_viewlet.interfaces import IViewletManager
    31 from pyams_viewlet.interfaces import IViewletManager
    27 
    32 
    28 
    33 
    29 __docformat__ = 'restructuredtext'
    34 __docformat__ = 'restructuredtext'
    30 
    35 
    31 from pyams_form import _
    36 from pyams_form import _  # pylint: disable=ungrouped-imports
    32 
    37 
    33 
    38 
    34 #
    39 #
    35 # Form interfaces
    40 # Form interfaces
    36 #
    41 #
   145         """Get an iterator over all forms and subforms"""
   150         """Get an iterator over all forms and subforms"""
   146 
   151 
   147     def get_widget_callback(self, widget):
   152     def get_widget_callback(self, widget):
   148         """Get submit callback associated with a given widget"""
   153         """Get submit callback associated with a given widget"""
   149 
   154 
   150     def update_content(self, object, data):
   155     def update_content(self, content, data):
   151         """Update given object with form data"""
   156         """Update given content with form data"""
   152 
       
   153     def get_submit_output(self, writer, changes):
       
   154         """Get submit output"""
       
   155 
   157 
   156 
   158 
   157 class IAJAXForm(Interface):
   159 class IAJAXForm(Interface):
   158     """AJAX form attributes"""
   160     """AJAX form attributes"""
   159 
   161 
   190     """Form widgets group interface"""
   192     """Form widgets group interface"""
   191 
   193 
   192     form = Object(title="Parent form",
   194     form = Object(title="Parent form",
   193                   schema=IForm)
   195                   schema=IForm)
   194 
   196 
       
   197     # pylint: disable=invalid-name
   195     id = TextLine(title="Group ID",
   198     id = TextLine(title="Group ID",
   196                   required=False)
   199                   required=False)
   197 
   200 
   198     widgets = List(title="Group's widgets list",
   201     widgets = List(title="Group's widgets list",
   199                    value_type=Object(schema=IWidget))
   202                    value_type=Object(schema=IWidget))
   230                              schema=IWidget,
   233                              schema=IWidget,
   231                              required=False,
   234                              required=False,
   232                              readonly=True)
   235                              readonly=True)
   233 
   236 
   234     checkbox_mode = Choice(title="Checkbox mode",
   237     checkbox_mode = Choice(title="Checkbox mode",
   235                            description="""To indicate if fieldset content should be hidden or disabled """
   238                            description="To indicate if fieldset content should be hidden or "
   236                                        """when the checkbox if not checked""",
   239                                        "disabled when the checkbox if not checked",
   237                            required=True,
   240                            required=True,
   238                            values=('disable', 'hide'),
   241                            values=('disable', 'hide'),
   239                            default='hide')
   242                            default='hide')
   240 
   243 
   241     display_mode = Choice(title="Group display mode",
   244     display_mode = Choice(title="Group display mode",
   242                           description="""If 'auto', a switchable group containing only """
   245                           description="If 'auto', a switchable group containing only "
   243                                       """widgets with default values is hidden; if 'always', group is always 
   246                                       "widgets with default values is hidden; if 'always', group "
   244                                       visible; if 'never', group is always hidden""",
   247                                       "is always visible; if 'never', group is always hidden",
   245                           values=('auto', 'never', 'always'),
   248                           values=('auto', 'never', 'always'),
   246                           required=True,
   249                           required=True,
   247                           default='never')
   250                           default='never')
   248 
   251 
   249     visible = Attribute("Visible group?")
   252     visible = Attribute("Visible group?")
   281                   value_type=Object(IFormWidgetsGroup))
   284                   value_type=Object(IFormWidgetsGroup))
   282 
   285 
   283     def add_group(self, group):
   286     def add_group(self, group):
   284         """Add given group to form groups"""
   287         """Add given group to form groups"""
   285 
   288 
   286     def updateGroups(self):
   289     def updateGroups(self):  # pylint: disable=invalid-name
   287         """Update inner groups state"""
   290         """Update inner groups state"""
   288 
   291 
   289 
   292 
   290 class IViewletsBasedForm(IBaseForm):
   293 class IViewletsBasedForm(IBaseForm):
   291     """Viewlets based form"""
   294     """Viewlets based form"""
   356 
   359 
   357 
   360 
   358 class ICustomUpdateSubForm(ISubForm):
   361 class ICustomUpdateSubForm(ISubForm):
   359     """SubForm interface with custom update method"""
   362     """SubForm interface with custom update method"""
   360 
   363 
   361     def update_content(self, object, data):
   364     def update_content(self, object, data):  # pylint: disable=redefined-builtin
   362         """Custom content update method"""
   365         """Custom content update method"""
   363 
   366 
   364 
   367 
   365 class ISearchForm(Interface):
   368 class ISearchForm(Interface):
   366     """Default search form interface"""
   369     """Default search form interface"""
   429 
   432 
   430     A form manager is an optional context/request/form multi-adapter which can be registered
   433     A form manager is an optional context/request/form multi-adapter which can be registered
   431     in some custom contexts to handle form custom settings.
   434     in some custom contexts to handle form custom settings.
   432     """
   435     """
   433 
   436 
   434     def getFields(self):
   437     def getFields(self):  # pylint: disable=invalid-name
   435         """Get form fields"""
   438         """Get form fields"""
   436 
   439 
   437     def update(self):
   440     def update(self):  # pylint: disable=invalid-name
   438         """Update form"""
   441         """Update form"""
   439 
   442 
   440     def updateWidgets(self, prefix=None):
   443     def updateWidgets(self, prefix=None):  # pylint: disable=invalid-name
   441         """Update form widgets"""
   444         """Update form widgets"""
   442 
   445 
   443     def updateActions(self):
   446     def updateActions(self):  # pylint: disable=invalid-name
   444         """Update form actions"""
   447         """Update form actions"""
   445 
   448 
   446     def updateGroups(self):
   449     def updateGroups(self):  # pylint: disable=invalid-name
   447         """Update form groups"""
   450         """Update form groups"""
   448 
   451 
   449 
   452 
   450 #
   453 #
   451 # Form buttons
   454 # Form buttons
   457         return False
   460         return False
   458     for widget in form.widgets.values():
   461     for widget in form.widgets.values():
   459         if widget.mode == INPUT_MODE:
   462         if widget.mode == INPUT_MODE:
   460             return True
   463             return True
   461     if IForm.providedBy(form):
   464     if IForm.providedBy(form):
   462         for subform in (form.subforms + form.tabforms):
   465         for subform in form.subforms + form.tabforms:
   463             for widget in (subform.widgets or {}).values():
   466             for widget in (subform.widgets or {}).values():
   464                 if widget.mode == INPUT_MODE:
   467                 if widget.mode == INPUT_MODE:
   465                     return True
   468                     return True
   466     return False
   469     return False
   467 
   470 
   628 
   631 
   629 @implementer(IFormObjectCreatedEvent)
   632 @implementer(IFormObjectCreatedEvent)
   630 class FormObjectCreatedEvent(ObjectCreatedEvent):
   633 class FormObjectCreatedEvent(ObjectCreatedEvent):
   631     """Form object created event"""
   634     """Form object created event"""
   632 
   635 
   633     def __init__(self, object, form):
   636     def __init__(self, object, form):  # pylint: disable=redefined-builtin
   634         super(FormObjectCreatedEvent, self).__init__(object)
   637         super(FormObjectCreatedEvent, self).__init__(object)
   635         self.form = form
   638         self.form = form
   636 
   639 
   637 
   640 
   638 class IFormObjectModifiedEvent(IObjectModifiedEvent, IFormObjectEvent):
   641 class IFormObjectModifiedEvent(IObjectModifiedEvent, IFormObjectEvent):
   641 
   644 
   642 @implementer(IFormObjectModifiedEvent)
   645 @implementer(IFormObjectModifiedEvent)
   643 class FormObjectModifiedEvent(ObjectModifiedEvent):
   646 class FormObjectModifiedEvent(ObjectModifiedEvent):
   644     """Form object modified event"""
   647     """Form object modified event"""
   645 
   648 
   646     def __init__(self, object, form, *descriptions):
   649     def __init__(self, object, form, *descriptions):  # pylint: disable=redefined-builtin
   647         ObjectModifiedEvent.__init__(self, object, *descriptions)
   650         ObjectModifiedEvent.__init__(self, object, *descriptions)
   648         self.form = form
   651         self.form = form