Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/email secretary after decisions #582

Merged
merged 6 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions reviews/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ def update_go(self, last_decision=None):
# For a review by commission:
else:
# Set the stage to CLOSING
from reviews.utils import notify_secretary_all_decisions
notify_secretary_all_decisions(self)
self.stage = self.CLOSING
self.save()
else:
Expand Down
18 changes: 18 additions & 0 deletions reviews/templates/mail/all_decisions_notify.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends "mail/base-internal.txt" %}

{% block content %}
Alle beoordelingen zijn toegevoegd bij de aanvraag {{ review.proposal.reference_number }}.

De review is klaar om afgesloten te worden.

Overzicht beoordelingen:
{% for decision in decisions %}
Beoordelaar: {{ decision.reviewer.get_full_name }}
Beoordeling: {{ decision.get_go_display }}
{% endfor %}

Detailpagina: {{ review_detail_page }}

Review afsluiten: {{ close_review_page }}

{% endblock %}
2 changes: 1 addition & 1 deletion reviews/templates/reviews/review_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<tbody>
{% for decision in review.decision_set.all %}
<tr>
<td>{{ decision.reviewer }}</td>
<td>{{ decision.reviewer.get_full_name }}</td>
<td>{{ decision.get_go_display|default:_("open") }}</td>
<td data-order="{{ decision.date_decision|date:'c' }}">{{ decision.date_decision|date:"j F Y, G:i" }}</td>
<td>{{ decision.comments }}</td>
Expand Down
4 changes: 2 additions & 2 deletions reviews/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ def test_decision_commission(self):
self.assertEqual(review.go, False) # no go

notify_secretary(decisions[1])
self.assertEqual(len(mail.outbox), 3)
self.assertIn(c, mail.outbox[2].body)
self.assertEqual(len(mail.outbox), 4)
self.assertIn(c, mail.outbox[3].body)

decisions[1].go = Decision.APPROVED
decisions[1].save()
Expand Down
29 changes: 28 additions & 1 deletion reviews/utils/review_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.core.mail import send_mail
from django.urls import reverse
from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import activate, get_language, ugettext_lazy as _
from django.utils import timezone

from main.models import YES, DOUBT
Expand Down Expand Up @@ -304,6 +304,33 @@ def notify_secretary(decision):
msg_plain = render_to_string('mail/decision_notify.txt', params)
send_mail(subject, msg_plain, settings.EMAIL_FROM, [secretary.email])

def notify_secretary_all_decisions(review):
"""
Notifies a secretary all Decisions have been made for a certain review
"""
# Change language to Dutch for this e-mail, but save the current language to reset it later
current_language = get_language()
activate("nl")

secretary = get_secretary()
subject = "FETC-GW {}: alle beoordelingen toegevoegd".format(
review.proposal.committee_prefixed_refnum(),
)
params = {
"secretary": secretary.get_full_name(),
"review": review,
"decisions": review.decision_set.all(),
"review_detail_page": settings.BASE_URL
+ (reverse("reviews:detail", args=[review.pk])),
"close_review_page": settings.BASE_URL
+ (reverse("reviews:close", args=[review.pk])),
}
msg_plain = render_to_string("mail/all_decisions_notify.txt", params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any translations existing in this input, e.g. decision.get_go_display, will render to the currently selected language.

If the user who triggered the update_go() happened to be set to English, all translations in here will also turn into English, which is a bit weird.

See proposal_utils.notify_local_staff() for an example of how we manually activate a language for email sending, and then reset it afterwards.

send_mail(subject, msg_plain, settings.EMAIL_FROM, [settings.EMAIL_FROM])

# Reset the current language
activate(current_language)


def notify_supervisor_nogo(decision):
secretary = get_secretary()
Expand Down
Loading