Commit c3ffc8bb authored by Michal Čihař's avatar Michal Čihař

Move suggestion notifications to suggestion adding code

parent 9e967a50
...@@ -879,20 +879,22 @@ class Unit(models.Model): ...@@ -879,20 +879,22 @@ class Unit(models.Model):
position__lte=self.position + appsettings.NEARBY_MESSAGES, position__lte=self.position + appsettings.NEARBY_MESSAGES,
) )
def add_suggestion(self, target, user): def add_suggestion(self, target, user, profile):
''' '''
Creates new suggestion for this unit. Creates new suggestion for this unit.
''' '''
from trans.models.unitdata import Suggestion, Change from trans.models.unitdata import Suggestion, Change
from accounts.models import Profile
# Create the suggestion # Create the suggestion
Suggestion.objects.create( suggestion = Suggestion.objects.create(
target=target, target=target,
checksum=self.checksum, checksum=self.checksum,
language=self.translation.language, language=self.translation.language,
project=self.translation.subproject.project, project=self.translation.subproject.project,
user=user user=user
) )
# Record in change # Record in change
Change.objects.create( Change.objects.create(
unit=self, unit=self,
...@@ -900,6 +902,25 @@ class Unit(models.Model): ...@@ -900,6 +902,25 @@ class Unit(models.Model):
translation=self.translation, translation=self.translation,
user=user user=user
) )
# Update suggestion count # Update suggestion count
self.translation.have_suggestion += 1 self.translation.have_suggestion += 1
self.translation.save() self.translation.save()
# Notify subscribed users
subscriptions = Profile.objects.subscribed_new_suggestion(
self.translation.subproject.project,
self.translation.language,
user
)
for subscription in subscriptions:
subscription.notify_new_suggestion(
self.translation,
suggestion,
self
)
# Update suggestion stats
if profile is not None:
profile.suggested += 1
profile.save()
...@@ -111,7 +111,8 @@ def translate(request, project, subproject, lang): ...@@ -111,7 +111,8 @@ def translate(request, project, subproject, lang):
# Create the suggestion # Create the suggestion
unit.add_suggestion( unit.add_suggestion(
join_plural(form.cleaned_data['target']), join_plural(form.cleaned_data['target']),
user user,
profile
) )
# Invite user to become translator if there is nobody else # Invite user to become translator if there is nobody else
recent_changes = Change.objects.content().filter( recent_changes = Change.objects.content().filter(
...@@ -124,18 +125,6 @@ def translate(request, project, subproject, lang): ...@@ -124,18 +125,6 @@ def translate(request, project, subproject, lang):
request, request,
_('There is currently no active translator for this translation, please consider becoming a translator as your suggestion might otherwise remain unreviewed.') _('There is currently no active translator for this translation, please consider becoming a translator as your suggestion might otherwise remain unreviewed.')
) )
# Notify subscribed users
subscriptions = Profile.objects.subscribed_new_suggestion(
obj.subproject.project,
obj.language,
request.user
)
for subscription in subscriptions:
subscription.notify_new_suggestion(obj, sug, unit)
# Update suggestion stats
if profile is not None:
profile.suggested += 1
profile.save()
elif not request.user.is_authenticated(): elif not request.user.is_authenticated():
# We accept translations only from authenticated # We accept translations only from authenticated
messages.error( messages.error(
......
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