Skip to content

Commit

Permalink
Send email when suggestions are rejected or accepted
Browse files Browse the repository at this point in the history
Accepting suggestion with changes does not yet send email.

Part of translate#5041.
  • Loading branch information
unho committed Aug 12, 2016
1 parent 10fadc0 commit f86e021
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
29 changes: 26 additions & 3 deletions pootle/apps/pootle_store/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from pootle.core.delegate import search_backend
from pootle.core.exceptions import Http400
from pootle.core.http import JsonResponse, JsonResponseBadRequest
from pootle.core.mail import send_mail
from pootle.core.utils import dateformat
from pootle.core.views import PootleJSON
from pootle_app.models.directory import Directory
Expand Down Expand Up @@ -620,7 +621,7 @@ def manage_suggestion(request, uid, sugg_id):
return accept_suggestion(request, uid, sugg_id)


def handle_suggestion_comment(request, suggestion, comment):
def handle_suggestion_comment(request, suggestion, unit, comment, action):
kwargs = {
'comment': comment,
'user': request.user,
Expand All @@ -629,6 +630,26 @@ def handle_suggestion_comment(request, suggestion, comment):
if comment_form.is_valid():
comment_form.save()

if action not in ("accepted", "rejected"):
return

ctx = {
'suggestion_id': suggestion.id,
'unit_url': request.build_absolute_uri(unit.get_translate_url()),
'comment': comment,
}
if action == "rejected":
message = loader.render_to_string(
'editor/email/suggestion_rejected_with_comment.txt', ctx)
subject = _(u"Suggestion %s rejected with comment" % suggestion.id)
else:
message = loader.render_to_string(
'editor/email/suggestion_accepted_with_comment.txt', ctx)
subject = _(u"Suggestion %s accepted with comment" % suggestion.id)

send_mail(subject, message, from_email=None,
recipient_list=[suggestion.user.email], fail_silently=True)


@get_unit_context()
def reject_suggestion(request, unit, suggid):
Expand All @@ -647,7 +668,8 @@ def reject_suggestion(request, unit, suggid):
unit.reject_suggestion(sugg, request.translation_project, request.user)
r_data = QueryDict(request.body)
if "comment" in r_data and r_data["comment"]:
handle_suggestion_comment(request, sugg, r_data["comment"])
handle_suggestion_comment(request, sugg, unit, r_data["comment"],
"rejected")

json = {
'udbid': unit.id,
Expand All @@ -666,7 +688,8 @@ def accept_suggestion(request, unit, suggid):

unit.accept_suggestion(suggestion, request.translation_project, request.user)
if "comment" in request.POST and request.POST["comment"]:
handle_suggestion_comment(request, suggestion, request.POST["comment"])
handle_suggestion_comment(request, suggestion, unit,
request.POST["comment"], "accepted")

json = {
'udbid': unit.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% load i18n %}
{% filter wordwrap:70 %}{% blocktrans %}Suggestion #{{ suggestion_id }} submitted by you for {{ unit_url }} has been accepted with the following comment:{% endblocktrans %}{% endfilter %}

{{ comment }}


{% filter wordwrap:70 %}{% blocktrans %}We hope this feedback will help you improve your future contributions.{% endblocktrans %}{% endfilter %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% load i18n %}
{% filter wordwrap:70 %}{% blocktrans %}Suggestion #{{ suggestion_id }} submitted by you for {{ unit_url }} has been rejected with the following comment:{% endblocktrans %}{% endfilter %}

{{ comment }}


{% filter wordwrap:70 %}{% blocktrans %}We hope this feedback will help you improve your future contributions.{% endblocktrans %}{% endfilter %}

0 comments on commit f86e021

Please sign in to comment.