Added events before and after widgets updates
authorThierry Florac <tflorac@ulthar.net>
Mon, 11 Jan 2021 15:45:53 +0100
changeset 216 33bbf7a09d29
parent 215 759c9ddac39e
child 217 45d0bf02540a
Added events before and after widgets updates
src/pyams_form/form.py
src/pyams_form/interfaces/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"""
--- 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"""