예제 #1
0
def save_logs_on_commit():
    logs = get_thread_variable('logs', [])
    for log in [x for x in logs if not x.pk]:
        instance = log.instance
        serializer = get_serializer(instance.__class__)()
        log.old = getattr(instance, '_old_values', None)
        log.new = serializer(instance)
        if log.force_save or log.old != log.new:
            log.save()

    if (settings.SAVE_RELATED and not get_thread_variable('disable_related')
            and any([x.pk for x in logs])):
        save_related(logs)
    del_thread_variable('logs')
    del_thread_variable('request')
예제 #2
0
def log_post_delete(sender, instance, **kwargs):
    if get_thread_variable('disable_logging'):
        return
    SimpleLog = get_log_model()
    instance._log = SimpleLog.log(instance,
                                  action_flag=SimpleLog.DELETE,
                                  old=instance._old_values,
                                  new=None)
예제 #3
0
def log_post_save(sender, instance, created, **kwargs):
    if get_thread_variable('disable_logging'):
        return
    if not hasattr(instance, '_log'):
        SimpleLog = get_log_model()
        instance._log = SimpleLog.log(
            instance,
            action_flag=SimpleLog.ADD if created else SimpleLog.CHANGE,
            commit=False)
예제 #4
0
def log_m2m_change(sender, instance, action, **kwargs):
    if get_thread_variable('disable_logging'):
        return
    SimpleLog = get_log_model()

    if action in ('pre_add', 'pre_remove', 'pre_clear'):
        SimpleLog.set_initial(instance)

    if action in ('post_add', 'post_remove', 'post_clear'):
        if not hasattr(instance, '_log'):
            instance._log = SimpleLog.log(instance,
                                          action_flag=SimpleLog.CHANGE,
                                          commit=False)
예제 #5
0
def log_pre_save_delete(sender, instance, **kwargs):
    if get_thread_variable('disable_logging'):
        return
    SimpleLog = get_log_model()
    SimpleLog.set_initial(instance)