# HG changeset patch # User Thierry Florac # Date 1540556870 -7200 # Node ID ff693a132cf07c1657e47142906f9cf437a017ac # Parent a9f8ef58c2c2c02cc50ec66cba6c6591f7900448 Update add form so that subforms context is always the newly created content and not their own context diff -r a9f8ef58c2c2 -r ff693a132cf0 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):