Update add form so that subforms context is always the newly created content and not their own context
--- 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):