Esempio n. 1
0
def m2m_pre_remove(sender, instance, action, reverse, model, pk_set, **kwargs):
    field = find_field(sender, instance)

    if field not in instance.audit.m2m_dirty:
        instance.audit.m2m_dirty[field] = {'added': [], 'removed': []}

    formatter = get_formatter(instance, field)
    instance.audit.m2m_dirty[field]['removed'].extend(map(formatter, pk_set))
Esempio n. 2
0
def special_audit(instance, field, action, value, **kwargs):
    """
    This handles special fields like Generic relations or
    OneToMany relationships. This signal MUST be triggered manually by the
    person wishing to track it
    `instance` is the instance the relationship is TO.
    `field` is the field name in instance.audit.fields
    `action` is the action you are tracking [added|removed]
    `value` is the value the action applies to, can be a pk, or some other value
        You should have a formatter for this in the instance model.
    """
    if not isinstance(instance, AuditedModel):
        return

    formatter = get_formatter(instance, field)
    admin_audit, public_audit = generate_audits(instance, action)
    value = formatter(value)

    added = ''
    removed = ''

    if action == 'added':
        added = value
    elif action == 'removed':
        removed = value

    add_group(admin_audit, instance.audit.fields[field].group)

    f = AuditM2MField(audit=admin_audit, name=field, added=added,
                      removed=removed, modified_by=instance.audit.modified_by)
    f.save()

    if instance.audit.fields[field].public:
        add_group(public_audit, instance.audit.fields[field].group)
        f = AuditM2MField(audit=public_audit, name=field, added=added,
                          removed=removed, modified_by=instance.audit.modified_by)
        f.save()