Commit 37b6793f authored by Michal Čihař's avatar Michal Čihař

Move suggestion adding to unit class

parent c7e010de
......@@ -878,3 +878,26 @@ class Unit(models.Model):
position__gte=self.position - appsettings.NEARBY_MESSAGES,
position__lte=self.position + appsettings.NEARBY_MESSAGES,
)
def add_suggestion(self, target):
'''
Creates new suggestion for this unit.
'''
# Create the suggestion
Suggestion.objects.create(
target=target,
checksum=self.checksum,
language=self.translation.language,
project=self.translation.subproject.project,
user=user
)
# Record in change
Change.objects.create(
unit=unit,
action=Change.ACTION_SUGGESTION,
translation=unit.translation,
user=user
)
# Update suggestion count
self.translation.have_suggestion += 1
self.translation.save()
......@@ -109,22 +109,9 @@ def translate(request, project, subproject, lang):
)
)
# Create the suggestion
sug = Suggestion.objects.create(
target=join_plural(form.cleaned_data['target']),
checksum=unit.checksum,
language=unit.translation.language,
project=unit.translation.subproject.project,
user=user
unit.add_suggestion(
join_plural(form.cleaned_data['target'])
)
# Record in change
Change.objects.create(
unit=unit,
action=Change.ACTION_SUGGESTION,
translation=unit.translation,
user=user
)
# Invalidate counts cache
unit.translation.invalidate_cache('suggestions')
# Invite user to become translator if there is nobody else
recent_changes = Change.objects.content().filter(
translation=unit.translation,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment