Update add form so that subforms context is always the newly created content and not their own context
authorThierry Florac <thierry.florac@onf.fr>
Fri, 26 Oct 2018 14:27:50 +0200
changeset 161 ff693a132cf0
parent 160 a9f8ef58c2c2
child 162 4e06e91893fd
Update add form so that subforms context is always the newly created content and not their own context
src/pyams_form/form.py
--- a/src/pyams_form/form.py	Fri Oct 26 10:00:32 2018 +0200
+++ b/src/pyams_form/form.py	Fri Oct 26 14:27:50 2018 +0200
@@ -368,6 +368,20 @@
             registry.notify(FormObjectCreatedEvent(object, self))
         return object
 
+    def update_content(self, content, data):
+        changes = applyChanges(self, content, data.get(self, data))
+        for subform in self.get_forms(include_self=False):
+            if subform.mode == DISPLAY_MODE:
+                continue
+            subform_update = ICustomUpdateSubForm(subform, None)
+            if subform_update is not None:
+                updates = subform_update.update_content(content, data.get(subform, data))
+                if isinstance(updates, dict):
+                    changes.update(updates)
+            else:
+                changes.update(applyChanges(subform, content, data.get(subform, data)))
+        return changes
+
 
 @adapter_config(context=(Interface, Interface, AddForm), provides=IFormContextPermissionChecker)
 class AddFormContextPermissionChecker(ContextRequestViewAdapter):