Commit 8d3a859d authored by Michal Čihař's avatar Michal Čihař

Automatically add vote to own suggestion (issue #248)

parent 6b9d33f7
......@@ -49,14 +49,16 @@ class RelatedUnitMixin(object):
class SuggestionManager(models.Manager):
def add(self, unit, target, user):
def add(self, unit, target, request):
'''
Creates new suggestion for this unit.
'''
from accounts.models import notify_new_suggestion
if not user.is_authenticated():
if not request.user.is_authenticated():
user = None
else:
user = request.user
# Create the suggestion
suggestion = Suggestion.objects.create(
......@@ -75,6 +77,14 @@ class SuggestionManager(models.Manager):
user=user
)
# Add unit vote
if user is not None and unit.can_vote_suggestions():
suggestion.add_vote(
unit.translation,
request,
True
)
# Notify subscribed users
notify_new_suggestion(unit, suggestion, user)
......
......@@ -207,7 +207,6 @@ def handle_translate(obj, request, user_locked, this_unit_url, next_unit_url):
if 'suggest' in request.POST:
# Handle suggesion saving
user = request.user
if form.cleaned_data['target'][0] == '':
messages.error(request, _('Your suggestion is empty!'))
# Stay on same entry
......@@ -228,7 +227,7 @@ def handle_translate(obj, request, user_locked, this_unit_url, next_unit_url):
Suggestion.objects.add(
unit,
join_plural(form.cleaned_data['target']),
user,
request,
)
elif not request.user.is_authenticated():
# We accept translations only from authenticated
......
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