Skip to content

Commit

Permalink
Save target field submission after state field always
Browse files Browse the repository at this point in the history
Fixes #4621
  • Loading branch information
ta2-1 committed May 13, 2016
1 parent 61d5862 commit 891f21f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
14 changes: 11 additions & 3 deletions pootle/apps/pootle_store/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down Expand Up @@ -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
Expand Down
22 changes: 12 additions & 10 deletions pootle/apps/pootle_store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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:
Expand All @@ -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] = [
Expand Down

0 comments on commit 891f21f

Please sign in to comment.