Skip to content

Commit

Permalink
Add backend support for suggestion alterations via submit
Browse files Browse the repository at this point in the history
Accepting a suggestion with alteration can be handled as:
- accepting the suggestion without alterations;
- editing accepted suggestion and submit new translation.
Refs. translate#4629
  • Loading branch information
ta2-1 committed Apr 22, 2016
1 parent 0f11a33 commit 9e11eb2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions pootle/apps/pootle_store/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ class Meta(object):
)
similarity = forms.FloatField(required=False)
mt_similarity = forms.FloatField(required=False)
suggestion_id = forms.IntegerField(required=False)

def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request', None)
Expand Down
24 changes: 24 additions & 0 deletions pootle/apps/pootle_store/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# or later license. See the LICENSE file for a copy of the license and the
# AUTHORS file for copyright and authorship information.

import copy

from translate.lang import data

from django import forms
Expand Down Expand Up @@ -507,6 +509,7 @@ def submit(request, unit):

translation_project = request.translation_project
language = translation_project.language
old_unit = copy.copy(unit)

if unit.hasplural():
snplurals = len(unit.source.strings)
Expand All @@ -520,8 +523,29 @@ def submit(request, unit):
form = form_class(request.POST, instance=unit, request=request)

if form.is_valid():
suggestion = None
suggid = form.cleaned_data['suggestion_id']
if suggid is not None:
try:
suggestion = unit.suggestion_set.get(id=suggid)
except ObjectDoesNotExist:
raise Http404

old_unit.accept_suggestion(suggestion,
request.translation_project, request.user)
if "comment" in request.POST and request.POST["comment"]:
kwargs = dict(
comment=request.POST["comment"],
user=request.user,
)
comment_form = UnsecuredCommentForm(suggestion, kwargs)
if comment_form.is_valid():
comment_form.save()

if form.updated_fields:
for field, old_value, new_value in form.updated_fields:
if field == SubmissionFields.TARGET and suggestion is not None:
old_value = suggestion.target_f
sub = Submission(
creation_time=current_time,
translation_project=translation_project,
Expand Down

0 comments on commit 9e11eb2

Please sign in to comment.