[damned-lies] Fixed action comment saving for UNDO action
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Fixed action comment saving for UNDO action
- Date: Sat, 24 Oct 2015 08:40:42 +0000 (UTC)
commit 06b420ff50da5bb4cf999dc6a318267ed3ba527b
Author: Claude Paroz <claude 2xlibre net>
Date: Sat Oct 24 10:39:57 2015 +0200
Fixed action comment saving for UNDO action
vertimus/models.py | 41 +++++++++++++++++++++--------------------
vertimus/tests/tests.py | 1 +
2 files changed, 22 insertions(+), 20 deletions(-)
---
diff --git a/vertimus/models.py b/vertimus/models.py
index e0046f5..63a51f6 100644
--- a/vertimus/models.py
+++ b/vertimus/models.py
@@ -444,15 +444,7 @@ class Action(ActionAbstract):
self.created = datetime.today()
super(Action, self).save(*args, **kwargs)
- 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('Not allowed')
- self.state_db = state
- if self.file:
- self.file.save(self.file.name, self.file, save=False)
- if form_data.get('comment'):
- self.comment = form_data['comment']
- self.save()
+ def update_state(self):
if self.target_state is not None:
# All actions change state except Writing a comment
self.state_db.change_state(self.target_state, self.person)
@@ -465,6 +457,17 @@ class Action(ActionAbstract):
arch_action = self.new_by_name('AA', person=self.person)
arch_action.apply_on(self.state_db, {})
+ 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('Not allowed')
+ self.state_db = state
+ if self.file:
+ self.file.save(self.file.name, self.file, save=False)
+ if form_data.get('comment'):
+ self.comment = form_data['comment']
+ self.save()
+ self.update_state()
+
if form_data.get('send_to_ml'):
self.send_mail_new_state(state, (state.language.team.mailing_list,))
elif self.send_mail_to_ml or self.comment:
@@ -728,12 +731,9 @@ class ActionUNDO(Action):
class Meta:
proxy = True
- def apply_on(self, state, form_data):
- self.state_db = state
- self.save()
-
- # Exclude WC because this action is a noop on State
- actions = Action.objects.filter(state_db__id=state.id).exclude(name='WC').order_by('-id')
+ def update_state(self):
+ # Look for the action to revert, excluding WC because this action is a noop on State
+ actions = Action.objects.filter(state_db__id=self.state_db.id).exclude(name='WC').order_by('-id')
skip_next = False
for action in actions:
if skip_next:
@@ -744,11 +744,12 @@ class ActionUNDO(Action):
skip_next = True
continue
# Found action to revert
- state.change_state(action.target_state, action.person)
- return
- state.change_state(StateNone)
- if form_data.get('send_to_ml'):
- self.send_mail_new_state(state, (state.language.team.mailing_list,))
+ self.state_db.change_state(action.target_state, action.person)
+ break
+ else:
+ # No revertable action found, reset to the None state
+ self.state_db.change_state(StateNone)
+
class ActionSeparator(object):
""" Fake action to add a separator in action menu """
diff --git a/vertimus/tests/tests.py b/vertimus/tests/tests.py
index 80a00ad..bb5e9e5 100644
--- a/vertimus/tests/tests.py
+++ b/vertimus/tests/tests.py
@@ -480,6 +480,7 @@ class VertimusTest(TeamsAndRolesTests):
action = Action.new_by_name('UNDO', person=self.pt)
action.apply_on(state, {'send_to_ml': action.send_mail_to_ml, 'comment': "Ooops! I don't want to do
that. Sorry."})
+ self.assertEqual(action.comment, "Ooops! I don't want to do that. Sorry.")
self.assertEqual(state.name, 'Translated')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]