mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Factorize some code using ContextDecorator.
This commit is contained in:
committed by
Simon Charette
parent
c9c0be31c5
commit
191d953c99
@@ -1,9 +1,7 @@
|
||||
from functools import wraps
|
||||
|
||||
from django.db import (
|
||||
connections, DEFAULT_DB_ALIAS,
|
||||
DatabaseError, Error, ProgrammingError)
|
||||
from django.utils.decorators import available_attrs
|
||||
from django.utils.decorators import ContextDecorator
|
||||
|
||||
|
||||
class TransactionManagementError(ProgrammingError):
|
||||
@@ -109,7 +107,7 @@ def set_rollback(rollback, using=None):
|
||||
# Decorators / context managers #
|
||||
#################################
|
||||
|
||||
class Atomic(object):
|
||||
class Atomic(ContextDecorator):
|
||||
"""
|
||||
This class guarantees the atomic execution of a given block.
|
||||
|
||||
@@ -285,13 +283,6 @@ class Atomic(object):
|
||||
else:
|
||||
connection.in_atomic_block = False
|
||||
|
||||
def __call__(self, func):
|
||||
@wraps(func, assigned=available_attrs(func))
|
||||
def inner(*args, **kwargs):
|
||||
with self:
|
||||
return func(*args, **kwargs)
|
||||
return inner
|
||||
|
||||
|
||||
def atomic(using=None, savepoint=True):
|
||||
# Bare decorator: @atomic -- although the first argument is called
|
||||
|
||||
Reference in New Issue
Block a user