Exemplo n.º 1
0
def save_logs_on_commit():
    all_logs = get_variable('simple_log_instances', {}).values()
    for log in [x for x in all_logs if not x.pk]:
        log.old = getattr(log.instance, '_old_value', None)
        log.new = serialize_instance(log.instance)
        if log.is_delete or log.old != log.new:
            log.save()

    if settings.SAVE_RELATED and any(
        [x.pk for x in all_logs if not x.disable_related]
    ):
        save_related(all_logs)
    del_variable('simple_log_instances')
Exemplo n.º 2
0
    def add_to_thread(cls, instance, obj):
        in_commit = save_logs_on_commit in [
            f[1] for f in connection.run_on_commit
        ]
        instances = get_variable('simple_log_instances', {})
        # prevent memory usage in non transaction test cases
        if not in_commit and instances:
            del_variable('simple_log_instances')
            instances = {}
        instances[instance] = obj
        set_variable('simple_log_instances', instances)

        if not in_commit:
            connection.on_commit(save_logs_on_commit)
Exemplo n.º 3
0
    def add_to_thread(cls, obj):
        in_commit = 'sl_in_commit' in \
                    [f[1].__name__ for f in connection.run_on_commit]
        logs = get_variable('logs', [])
        # prevent memory usage in non transaction test cases
        if not in_commit and logs:
            del_variable('logs')
            logs = []
        logs.append(obj)
        set_variable('logs', logs)

        if not in_commit:

            def sl_in_commit():
                save_logs_on_commit(logs)

            connection.on_commit(sl_in_commit)
Exemplo n.º 4
0
 def __exit__(self, *exc):
     del_variable('disable_related')
Exemplo n.º 5
0
 def __exit__(self, *exc):
     del_variable('disable_logging')
Exemplo n.º 6
0
 def test_del_variable(self):
     REQUEST_VARS.test = 'test'
     del_variable('test')
     self.assertFalse(hasattr(REQUEST_VARS, 'test'))