[damned-lies] [vertimus] Do not initially save StateNone states
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] [vertimus] Do not initially save StateNone states
- Date: Wed, 28 Mar 2018 19:00:20 +0000 (UTC)
commit 09911c0f14dd14ebfab401236d762633276e98eb
Author: Claude Paroz <claude 2xlibre net>
Date: Wed Mar 28 20:58:55 2018 +0200
[vertimus] Do not initially save StateNone states
vertimus/models.py | 2 ++
vertimus/tests/tests.py | 9 ++-------
vertimus/views.py | 10 +++-------
3 files changed, 7 insertions(+), 14 deletions(-)
---
diff --git a/vertimus/models.py b/vertimus/models.py
index ab23cca..178d893 100644
--- a/vertimus/models.py
+++ b/vertimus/models.py
@@ -454,6 +454,8 @@ class Action(ActionAbstract):
def apply_on(self, state, form_data):
if not self.name in [a.name for a in state.get_available_actions(self.person)]:
raise Exception('Action not allowed')
+ if state.pk is None:
+ state.save()
self.state_db = state
if self.file:
self.file.save(self.file.name, self.file, save=False)
diff --git a/vertimus/tests/tests.py b/vertimus/tests/tests.py
index 2ec5e30..36e0f88 100644
--- a/vertimus/tests/tests.py
+++ b/vertimus/tests/tests.py
@@ -217,7 +217,6 @@ class VertimusTest(TeamsAndRolesTests):
def test_action_menu(self):
state = StateNone(branch=self.b, domain=self.d, language=self.l)
- state.save()
form = ActionForm(self.pt, state, state.get_available_actions(self.pt), False)
self.assertHTMLEqual(
str(form['action']),
@@ -240,7 +239,7 @@ class VertimusTest(TeamsAndRolesTests):
def test_action_wc(self):
state = StateNone(branch=self.b, domain=self.d, language=self.l)
- state.save()
+ # State may be initially unsaved
prev_updated = state.updated
action = Action.new_by_name('WC', person=self.pt)
@@ -270,7 +269,6 @@ class VertimusTest(TeamsAndRolesTests):
def test_action_rt(self):
state = StateNone(branch=self.b, domain=self.d, language=self.l)
- state.save()
action = Action.new_by_name('RT', person=self.pt)
action.apply_on(state, {'send_to_ml': action.send_mail_to_ml, 'comment': "Reserved!"})
@@ -522,7 +520,6 @@ class VertimusTest(TeamsAndRolesTests):
def test_action_undo(self):
state = StateNone(branch=self.b, domain=self.d, language=self.l)
- state.save()
action = Action.new_by_name('RT', person=self.pt)
action.apply_on(state, {'send_to_ml': action.send_mail_to_ml, 'comment': "Reserved!"})
@@ -584,7 +581,6 @@ class VertimusTest(TeamsAndRolesTests):
def test_delete(self):
""" Test that a whole module tree can be properly deleted """
state = StateNone(branch=self.b, domain=self.d, language=self.l)
- state.save()
action = Action.new_by_name('WC', person=self.pt)
action.apply_on(state, {'send_to_ml': action.send_mail_to_ml, 'comment': "Hi!"})
@@ -619,7 +615,7 @@ class VertimusTest(TeamsAndRolesTests):
response = self.client.post(url, data={
'action': 'WC',
- 'comment': 'Graçias', 'send_to_ml': '', 'author': str(self.pn.pk)
+ 'comment': 'Graçias', 'send_to_ml': '',
}, follow=True)
self.assertContains(response, 'Graçias')
@@ -664,7 +660,6 @@ class VertimusTest(TeamsAndRolesTests):
def test_feeds(self):
state = StateNone(branch=self.b, domain=self.d, language=self.l)
- state.save()
action = Action.new_by_name('RT', person=self.pt)
action.apply_on(state, {'send_to_ml': action.send_mail_to_ml, 'comment': "Translating"})
diff --git a/vertimus/views.py b/vertimus/views.py
index 182911d..c40adcb 100644
--- a/vertimus/views.py
+++ b/vertimus/views.py
@@ -59,14 +59,10 @@ def vertimus(request, branch, domain, language, stats=None, level="0"):
# Get the state of the translation
try:
- state, created = State.objects.get_or_create(
- branch=branch,
- domain=domain,
- language=language)
- except IntegrityError:
- # MySQL is subject to a race condition with default REPEATABLE READ isolation level
- # See https://code.djangoproject.com/ticket/13906
state = State.objects.get(branch=branch, domain=domain, language=language)
+ except State.DoesNotExist:
+ # No need to save the state at this stage
+ state = State(branch=branch, domain=domain, language=language)
# Filtering on domain.name instead of domain because we can have several domains
# working on the same set of strings (e.g. when an extraction method changed,
# each extraction is mapped to a different domain with branch_from/branch_to delimitations)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]