예제 #1
0
def apply_data_event(fields, content, data, event=ObjectModifiedEvent):
    """ Updates the object with the data and sends an IObjectModifiedEvent
    """
    changes = set_fields_data(fields, content, data)
    if changes:
        if IDataManager.providedBy(content):
            notify_changes(content.content, changes, event)
        else:
            notify_changes(content, changes, event)
    return changes
예제 #2
0
def set_fields_data(fields, content, data):
    """Applies the values to the fields, if a change has been made and
    if the field is present in the given fields manager. It returns a
    dictionnary describing the changes applied with the name of the field
    and the interface from where it's from.
    """
    changes = {}
    if not IDataManager.providedBy(content):
        content = ObjectDataManager(content)

    for identifier, value in data.items():
        field = fields.get(identifier, default=None)
        if field is None or value is NO_VALUE or value is NO_CHANGE:
            continue

        content.set(identifier, value)
        changes.setdefault(field.interface, []).append(identifier)

    return changes