def applyChanges(self, content, data): """ Apply changes """ data['request'] = self.request changes = {} for name, field in self.fields.items(): # If the field is not in the data, then go on to the next one try: newValue = data[name] except KeyError: continue # If the value is NOT_CHANGED, ignore it, since the widget/converter # sent a strong message not to do so. if newValue is interfaces.NOT_CHANGED: continue if util.changedField(field.field, newValue, context=content): # Only update the data, if it is different dm = queryMultiAdapter((content, field.field), interfaces.IDataManager) # Custom behaviour. Send data instead of newValue for more # flexibility dm.set(data) # Record the change using information required later changes.setdefault(dm.field.interface, []).append(name) return changes
def applyChanges(self, content, data): """ Apply changes """ data['request'] = self.request changes = {} for name, field in self.fields.items(): # If the field is not in the data, then go on to the next one try: newValue = data[name] except KeyError: continue # If the value is NOT_CHANGED, ignore it, since the widget/converter # sent a strong message not to do so. if newValue is interfaces.NOT_CHANGED: continue if util.changedField(field.field, newValue, context=content): # Only update the data, if it is different dm = queryMultiAdapter( (content, field.field), interfaces.IDataManager) # Custom behaviour. Send data instead of newValue for more # flexibility dm.set(data) # Record the change using information required later changes.setdefault(dm.field.interface, []).append(name) return changes
def applyChanges(form, content, data): changes = {} for name, field in form.fields.items(): # If the field is not in the data, then go on to the next one try: newValue = data[name] except KeyError: continue # If the value is NOT_CHANGED, ignore it, since the widget/converter # sent a strong message not to do so. if newValue is interfaces.NOT_CHANGED: continue if util.changedField(field.field, newValue, context=content): # Only update the data, if it is different dm = zope.component.getMultiAdapter((content, field.field), interfaces.IDataManager) dm.set(newValue) # Record the change using information required later changes.setdefault(dm.field.interface, []).append(name) return changes
def applyChanges(form, content, data): changes = {} for name, field in form.fields.items(): # If the field is not in the data, then go on to the next one try: newValue = data[name] except KeyError: continue # If the value is NOT_CHANGED, ignore it, since the widget/converter # sent a strong message not to do so. if newValue is interfaces.NOT_CHANGED: continue if util.changedField(field.field, newValue, context=content): # Only update the data, if it is different dm = zope.component.getMultiAdapter( (content, field.field), interfaces.IDataManager) dm.set(newValue) # Record the change using information required later changes.setdefault(dm.field.interface, []).append(name) return changes
def _applyChanges(form, content, data, force=False): # This is copied from z3c.form, but modified to add # an option to always set values even if already set. changes = {} for name, field in form.fields.items(): # If the field is not in the data, then go on to the next one try: newValue = data[name] except KeyError: continue # If the value is NOT_CHANGED, ignore it, since the widget/converter # sent a strong message not to do so. if newValue is NOT_CHANGED: continue if force or changedField(field.field, newValue, context=content): # Only update the data, if it is different dm = getMultiAdapter((content, field.field), IDataManager) dm.set(newValue) # Record the change using information required later changes.setdefault(dm.field.interface, []).append(name) return changes
def save_form( # noqa: C901 (this has gotten quite complex) form, data, submission, default_values=False, force=False, ): changes = {} for name, field in form.fields.items(): if name == 'schema': continue elif name not in data and default_values: value = field.field.default adapter = queryMultiAdapter( ( form.context, form.request, form, field.field, form.widgets[name], ), IValue, name='default', ) if adapter: value = adapter.get() elif name not in data: continue else: value = data[name] if value is NOT_CHANGED: continue # Set contained information of schema.Object if IContained.providedBy(value): value.__name__ = name value.__parent__ = aq_base(submission) # Set contained information of schema.List|Tuple(value_type=Object) if isinstance(value, list) or isinstance(value, tuple): for item in value: if IContained.providedBy(item): item.__name__ = name item.__parent__ = aq_base(submission) if force: setattr(submission, name, value) elif changedField(field.field, value, context=submission): # Only update the data, if it is different dm = getMultiAdapter((submission, field.field), IDataManager) dm.set(value) # Record the change using information required later changes.setdefault(dm.field.interface, []).append(name) try: for group in form.groups: changes.update( save_form(group, data, submission, default_values, force), ) except AttributeError: pass return changes