49 |
49 |
{
|
50 |
50 |
'saved': {},
|
51 |
51 |
'deleted': {},
|
52 |
|
'in_atomic_block': connection.in_atomic_block,
|
53 |
52 |
}
|
54 |
53 |
)
|
55 |
54 |
|
... | ... | |
61 |
60 |
return
|
62 |
61 |
|
63 |
62 |
context = self.stack.pop()
|
64 |
|
context.pop('in_atomic_block')
|
65 |
63 |
|
66 |
64 |
if provision:
|
67 |
65 |
|
... | ... | |
88 |
86 |
if not self.stack:
|
89 |
87 |
return
|
90 |
88 |
|
91 |
|
in_atomic_block = self.stack[-1]['in_atomic_block']
|
|
89 |
# prevent losing pk of the model instances between call to add_saved
|
|
90 |
# and its execution at the end of the current transaction
|
|
91 |
instances = [copy.copy(instance) for instance in args]
|
|
92 |
saved = self.saved
|
92 |
93 |
|
93 |
94 |
def callback():
|
94 |
|
for instance in args:
|
|
95 |
for instance in instances:
|
95 |
96 |
klass = User if isinstance(instance, User) else Role
|
96 |
|
self.saved.setdefault(klass, set()).add(instance)
|
|
97 |
saved.setdefault(klass, set()).add(instance)
|
97 |
98 |
|
98 |
|
if in_atomic_block:
|
99 |
|
callback()
|
100 |
|
else:
|
101 |
|
transaction.on_commit(callback)
|
|
99 |
transaction.on_commit(callback)
|
102 |
100 |
|
103 |
101 |
def add_deleted(self, *args):
|
104 |
102 |
if not self.stack:
|
105 |
103 |
return
|
106 |
104 |
|
107 |
|
in_atomic_block = self.stack[-1]['in_atomic_block']
|
|
105 |
# prevent losing pk of the model instances between call to add_saved
|
|
106 |
# and its execution at the end of the current transaction
|
|
107 |
instances = [copy.copy(instance) for instance in args]
|
|
108 |
deleted = self.deleted
|
|
109 |
saved = self.saved
|
108 |
110 |
|
109 |
111 |
def callback():
|
110 |
|
for instance in args:
|
|
112 |
for instance in instances:
|
111 |
113 |
klass = User if isinstance(instance, User) else Role
|
112 |
|
self.deleted.setdefault(klass, set()).add(instance)
|
113 |
|
self.saved.get(klass, set()).discard(instance)
|
|
114 |
deleted.setdefault(klass, set()).add(instance)
|
|
115 |
saved.get(klass, set()).discard(instance)
|
114 |
116 |
|
115 |
|
if in_atomic_block:
|
116 |
|
callback()
|
117 |
|
else:
|
118 |
|
transaction.on_commit(callback)
|
|
117 |
transaction.on_commit(callback)
|
119 |
118 |
|
120 |
119 |
def resolve_ou(self, instances, ous):
|
121 |
120 |
for instance in instances:
|