Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/import_export/utils.py: 43%
15 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1from django.db import transaction
4class atomic_if_using_transaction:
5 """Context manager wraps `atomic` if `using_transactions`.
7 Replaces code::
9 if using_transactions:
10 with transaction.atomic(using=using):
11 return something()
12 return something()
13 """
14 def __init__(self, using_transactions, using):
15 self.using_transactions = using_transactions
16 if using_transactions:
17 self.context_manager = transaction.atomic(using=using)
19 def __enter__(self):
20 if self.using_transactions:
21 self.context_manager.__enter__()
23 def __exit__(self, *args):
24 if self.using_transactions:
25 self.context_manager.__exit__(*args)
28def original(method):
29 """
30 A decorator used to mark some class methods as 'original',
31 making it easy to detect whether they have been overridden
32 by a subclass. Useful for method deprecation.
33 """
34 method.is_original = True
35 return method