From 891f21fb2801c035dbede18cbba6947a2259ce6e Mon Sep 17 00:00:00 2001 From: Taras Semenenko Date: Wed, 11 May 2016 14:49:57 +0300 Subject: [PATCH] Save target field submission after state field always Fixes #4621 --- pootle/apps/pootle_store/forms.py | 14 +++++++++++--- pootle/apps/pootle_store/models.py | 22 ++++++++++++---------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/pootle/apps/pootle_store/forms.py b/pootle/apps/pootle_store/forms.py index e01c0da7564..66cbf1c011c 100644 --- a/pootle/apps/pootle_store/forms.py +++ b/pootle/apps/pootle_store/forms.py @@ -267,17 +267,25 @@ class Meta(object): def __init__(self, *args, **kwargs): self.request = kwargs.pop('request', None) super(UnitForm, self).__init__(*args, **kwargs) - self.updated_fields = [] + self._updated_fields = [] self.fields['target_f'].widget.attrs['data-translation-aid'] = \ self['target_f'].value() + @property + def updated_fields(self): + order_dict = { + SubmissionFields.STATE: 0, + SubmissionFields.TARGET: 1, + } + return sorted(self._updated_fields, key=lambda x: order_dict[x[0]]) + def clean_target_f(self): value = self.cleaned_data['target_f'] if self.instance.target.strings != multistring(value or [u'']): self.instance._target_updated = True - self.updated_fields.append((SubmissionFields.TARGET, + self._updated_fields.append((SubmissionFields.TARGET, to_db(self.instance.target), to_db(value))) @@ -347,7 +355,7 @@ def clean(self): if old_state not in [new_state, OBSOLETE]: self.instance._state_updated = True - self.updated_fields.append((SubmissionFields.STATE, + self._updated_fields.append((SubmissionFields.STATE, old_state, new_state)) self.cleaned_data['state'] = new_state diff --git a/pootle/apps/pootle_store/models.py b/pootle/apps/pootle_store/models.py index b434c60703a..16526020288 100644 --- a/pootle/apps/pootle_store/models.py +++ b/pootle/apps/pootle_store/models.py @@ -12,6 +12,8 @@ import os from hashlib import md5 +from collections import OrderedDict + from translate.filters.decorators import Category from translate.storage import base @@ -1138,11 +1140,11 @@ def accept_suggestion(self, suggestion, translation_project, reviewer): suggestion.review_time = current_time suggestion.save() - create_subs = {} - create_subs[SubmissionFields.TARGET] = [old_target, self.target] + create_subs = OrderedDict() if old_state != self.state: create_subs[SubmissionFields.STATE] = [old_state, self.state] self.store.mark_dirty(CachedMethods.WORDCOUNT_STATS) + create_subs[SubmissionFields.TARGET] = [old_target, self.target] for field in create_subs: kwargs = { @@ -1576,14 +1578,7 @@ def record_submissions(self, unit, old_target, old_state, current_time, being available in `unit`. Let's look into replacing such members with something saner (#3895). """ - create_subs = {} - - # FIXME: extreme implicit hazard - if unit._target_updated: - create_subs[SubmissionFields.TARGET] = [ - old_target, - unit.target_f, - ] + create_subs = OrderedDict() # FIXME: extreme implicit hazard if unit._state_updated: @@ -1592,6 +1587,13 @@ def record_submissions(self, unit, old_target, old_state, current_time, unit.state, ] + # FIXME: extreme implicit hazard + if unit._target_updated: + create_subs[SubmissionFields.TARGET] = [ + old_target, + unit.target_f, + ] + # FIXME: extreme implicit hazard if unit._comment_updated: create_subs[SubmissionFields.COMMENT] = [