# HG changeset patch # User Thierry Florac # Date 1610376353 -3600 # Node ID 33bbf7a09d292ad789b2c9baa7c6e6fd8d667c90 # Parent 759c9ddac39ebf61a616ed1fabebc6f624668941 Added events before and after widgets updates diff -r 759c9ddac39e -r 33bbf7a09d29 src/pyams_form/form.py --- a/src/pyams_form/form.py Mon Jul 20 14:37:35 2020 +0200 +++ b/src/pyams_form/form.py Mon Jan 11 15:45:53 2021 +0100 @@ -41,9 +41,9 @@ from pyams_form.group import GroupsBasedForm from pyams_form.interfaces import get_form_weight -from pyams_form.interfaces.form import FormCreatedEvent, IAJAXForm, ICustomUpdateSubForm, IForm, \ - IFormContextPermissionChecker, IFormCreatedEvent, IFormLayer, IInnerForm, IInnerSubForm, \ - IInnerTabForm +from pyams_form.interfaces.form import BeforeFormWidgetsUpdateEvent, FormCreatedEvent, FormWidgetsUpdatedEvent, \ + IAJAXForm, ICustomUpdateSubForm, IForm, IFormContextPermissionChecker, IFormCreatedEvent, \ + IFormLayer, IInnerForm, IInnerSubForm, IInnerTabForm from pyams_form.interfaces.form import FormObjectCreatedEvent, FormObjectModifiedEvent from pyams_form.interfaces.form import IAddFormButtons, IEditFormButtons, IModalAddFormButtons, \ IModalDisplayFormButtons, IModalEditFormButtons @@ -148,9 +148,11 @@ def updateWidgets(self, prefix=None): """Update form's widgets""" + self.request.registry.notify(BeforeFormWidgetsUpdateEvent(self)) super(BaseForm, self).updateWidgets(prefix) if not self._groups: self.updateGroups() + self.request.registry.notify(FormWidgetsUpdatedEvent(self)) def get_form_action(self): """Get action associated with form""" diff -r 759c9ddac39e -r 33bbf7a09d29 src/pyams_form/interfaces/form.py --- a/src/pyams_form/interfaces/form.py Mon Jul 20 14:37:35 2020 +0200 +++ b/src/pyams_form/interfaces/form.py Mon Jan 11 15:45:53 2021 +0100 @@ -657,3 +657,21 @@ def __init__(self, object, form, *descriptions): # pylint: disable=redefined-builtin ObjectModifiedEvent.__init__(self, object, *descriptions) self.form = form + + +class IBeforeFormWidgetsUpdateEvent(IObjectEvent): + """Form before-update event interface""" + + +@implementer(IBeforeFormWidgetsUpdateEvent) +class BeforeFormWidgetsUpdateEvent(ObjectEvent): + """Form before-update event""" + + +class IFormWidgetsUpdatedEvent(IObjectEvent): + """Form updated event interface""" + + +@implementer(IFormWidgetsUpdatedEvent) +class FormWidgetsUpdatedEvent(ObjectEvent): + """Form updated event"""