Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
django-taggit
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a56e1185
authored
Mar 01, 2014
by
Florian Apolloner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use transaction.atomic when available.
parent
a0b63448
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
5 deletions
+19
-5
taggit/models.py
+19
-5
No files found.
taggit/models.py
View file @
a56e1185
...
@@ -9,6 +9,23 @@ from django.utils.translation import ugettext_lazy as _, ugettext
...
@@ -9,6 +9,23 @@ from django.utils.translation import ugettext_lazy as _, ugettext
from
django.utils.encoding
import
python_2_unicode_compatible
from
django.utils.encoding
import
python_2_unicode_compatible
try
:
atomic
=
transaction
.
atomic
except
AttributeError
:
from
contextlib
import
contextmanager
@contextmanager
def
atomic
(
using
=
None
):
sid
=
transaction
.
savepoint
(
using
=
using
)
try
:
yield
except
IntegrityError
:
transaction
.
savepoint_rollback
(
sid
,
using
=
using
)
raise
else
:
transaction
.
savepoint_commit
(
sid
,
using
=
using
)
@python_2_unicode_compatible
@python_2_unicode_compatible
class
TagBase
(
models
.
Model
):
class
TagBase
(
models
.
Model
):
name
=
models
.
CharField
(
verbose_name
=
_
(
'Name'
),
unique
=
True
,
max_length
=
100
)
name
=
models
.
CharField
(
verbose_name
=
_
(
'Name'
),
unique
=
True
,
max_length
=
100
)
...
@@ -30,17 +47,14 @@ class TagBase(models.Model):
...
@@ -30,17 +47,14 @@ class TagBase(models.Model):
# with a multi-master setup, theoretically we could try to
# with a multi-master setup, theoretically we could try to
# write and rollback on different DBs
# write and rollback on different DBs
kwargs
[
"using"
]
=
using
kwargs
[
"using"
]
=
using
trans_kwargs
=
{
"using"
:
using
}
i
=
0
i
=
0
while
True
:
while
True
:
i
+=
1
i
+=
1
try
:
try
:
sid
=
transaction
.
savepoint
(
**
trans_kwargs
)
with
atomic
(
using
=
using
):
res
=
super
(
TagBase
,
self
)
.
save
(
*
args
,
**
kwargs
)
res
=
super
(
TagBase
,
self
)
.
save
(
*
args
,
**
kwargs
)
transaction
.
savepoint_commit
(
sid
,
**
trans_kwargs
)
return
res
return
res
except
IntegrityError
:
except
IntegrityError
:
transaction
.
savepoint_rollback
(
sid
,
**
trans_kwargs
)
self
.
slug
=
self
.
slugify
(
self
.
name
,
i
)
self
.
slug
=
self
.
slugify
(
self
.
name
,
i
)
else
:
else
:
return
super
(
TagBase
,
self
)
.
save
(
*
args
,
**
kwargs
)
return
super
(
TagBase
,
self
)
.
save
(
*
args
,
**
kwargs
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment