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')
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)
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)
def __exit__(self, *exc): del_variable('disable_related')
def __exit__(self, *exc): del_variable('disable_logging')
def test_del_variable(self): REQUEST_VARS.test = 'test' del_variable('test') self.assertFalse(hasattr(REQUEST_VARS, 'test'))