Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
janno42 committed Dec 15, 2022
2 parents 51b0e51 + e38b5f7 commit f44d9d5
Show file tree
Hide file tree
Showing 21 changed files with 559 additions and 278 deletions.
4 changes: 2 additions & 2 deletions evap/development/fixtures/test_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -128389,8 +128389,8 @@
"fields": {
"name": "Text Answer Review Reminder",
"subject": "[EvaP] Bitte Textantworten überprüfen / Please review text answers",
"plain_content": "(English version below)\r\n\r\n\r\nHallo {{ user.first_name }},\r\n\r\nes gibt noch nicht überprüfte Textantworten für eine oder mehrere Evaluierungen, bei denen der Evaluierungszeitraum abgelaufen ist und nicht mehr auf Notenveröffentlichungen gewartet werden muss. Bitte überprüfe die Textantworten für diese Evaluierungen möglichst bald:\r\n{% for evaluation in evaluations %} - {{ evaluation.full_name_de }}\r\n{% endfor %}\r\n\r\n(Dies ist eine automatisch versendete E-Mail.)\r\n\r\n\r\n--\r\n\r\n\r\nDear {{ user.first_name }},\r\n\r\nthere are text answers not yet reviewed for one or more evaluations where the evaluation period has ended and there is no need to wait for grade publishing. Please review the text answers for these evaluations as soon as possible:\r\n{% for evaluation in evaluations %} - {{ evaluation.full_name_en }}\r\n{% endfor %}\r\n\r\n(This is an automated message.)",
"html_content": "<i>(English version below)</i><br /><br /><br />\r\n\r\n\r\nHallo {{ user.first_name }},<br /><br />\r\n\r\nes gibt noch nicht überprüfte Textantworten für eine oder mehrere Evaluierungen, bei denen der Evaluierungszeitraum abgelaufen ist und nicht mehr auf Notenveröffentlichungen gewartet werden muss. Bitte überprüfe die Textantworten für diese Evaluierungen möglichst bald:\r\n<ul>{% for evaluation in evaluations %}\r\n<li>{{ evaluation.full_name_de }}</li>\r\n{% endfor %}</ul><br /><br />\r\n\r\n<i>(Dies ist eine automatisch versendete E-Mail.)</i><br /><br />\r\n\r\n<hr><br /><br />\r\n\r\nDear {{ user.first_name }},<br /><br />\r\n\r\nthere are text answers not yet reviewed for one or more evaluations where the evaluation period has ended and there is no need to wait for grade publishing. Please review the text answers for these evaluations as soon as possible:\r\n<ul>{% for evaluation in evaluations %}\r\n<li>{{ evaluation.full_name_en }}</li>\r\n{% endfor %}</ul><br /><br />\r\n\r\n<i>(This is an automated message.)</i>"
"plain_content": "(English version below)\r\n\r\n\r\nHallo {{ user.first_name }},\r\n\r\nes gibt noch nicht überprüfte Textantworten für eine oder mehrere Evaluierungen, bei denen der Evaluierungszeitraum abgelaufen ist und nicht mehr auf Notenveröffentlichungen gewartet werden muss. Bitte überprüfe die Textantworten für diese Evaluierungen möglichst bald:\r\n{% for evaluation, url in evaluation_url_tuples %} - {{ evaluation.full_name_de }} ({{ url }})\r\n{% endfor %}\r\n\r\n(Dies ist eine automatisch versendete E-Mail.)\r\n\r\n\r\n--\r\n\r\n\r\nDear {{ user.first_name }},\r\n\r\nthere are text answers not yet reviewed for one or more evaluations where the evaluation period has ended and there is no need to wait for grade publishing. Please review the text answers for these evaluations as soon as possible:\r\n{% for evaluation, url in evaluation_url_tuples %} - {{ evaluation.full_name_en }} ({{ url }})\r\n{% endfor %}\r\n\r\n(This is an automated message.)",
"html_content": "<i>(English version below)</i><br /><br /><br />\r\n\r\n\r\nHallo {{ user.first_name }},<br /><br />\r\n\r\nes gibt noch nicht überprüfte Textantworten für eine oder mehrere Evaluierungen, bei denen der Evaluierungszeitraum abgelaufen ist und nicht mehr auf Notenveröffentlichungen gewartet werden muss. Bitte überprüfe die Textantworten für diese Evaluierungen möglichst bald:\r\n<ul>{% for evaluation, url in evaluation_url_tuples %}\r\n<li><a href='{{ url }}'>{{ evaluation.full_name_de }}</a></li>\r\n{% endfor %}</ul><br /><br />\r\n\r\n<i>(Dies ist eine automatisch versendete E-Mail.)</i><br /><br />\r\n\r\n<hr><br /><br />\r\n\r\nDear {{ user.first_name }},<br /><br />\r\n\r\nthere are text answers not yet reviewed for one or more evaluations where the evaluation period has ended and there is no need to wait for grade publishing. Please review the text answers for these evaluations as soon as possible:\r\n<ul>{% for evaluation, url in evaluation_url_tuples %}\r\n<li><a href='{{ url }}'>{{ evaluation.full_name_en }}</a></li>\r\n{% endfor %}</ul><br /><br />\r\n\r\n<i>(This is an automated message.)</i>"
}
},
{
Expand Down
33 changes: 25 additions & 8 deletions evap/evaluation/management/commands/send_reminders.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
import datetime
import logging
from typing import List, Tuple

from django.conf import settings
from django.contrib.auth.models import Group
from django.core.management.base import BaseCommand
from django.urls import reverse

from evap.evaluation.management.commands.tools import log_exceptions
from evap.evaluation.models import EmailTemplate, Evaluation

logger = logging.getLogger(__name__)


def get_sorted_evaluation_url_tuples_with_urgent_review() -> List[Tuple[Evaluation, str]]:
evaluation_url_tuples: List[Tuple[Evaluation, str]] = [
(
evaluation,
settings.PAGE_URL
+ reverse(
"staff:evaluation_textanswers",
kwargs={"semester_id": evaluation.course.semester.id, "evaluation_id": evaluation.id},
),
)
for evaluation in Evaluation.objects.filter(state=Evaluation.State.EVALUATED)
if evaluation.textanswer_review_state == Evaluation.TextAnswerReviewState.REVIEW_URGENT
]
evaluation_url_tuples = sorted(
evaluation_url_tuples, key=lambda evaluation_url_tuple: evaluation_url_tuple[0].full_name
)
return evaluation_url_tuples


@log_exceptions
class Command(BaseCommand):
help = "Sends email reminders X days before evaluation ends and reminds managers to review text answers."
Expand Down Expand Up @@ -49,16 +70,12 @@ def send_student_reminders():
@staticmethod
def send_textanswer_reminders():
if datetime.date.today().weekday() in settings.TEXTANSWER_REVIEW_REMINDER_WEEKDAYS:
evaluations = [
evaluation
for evaluation in Evaluation.objects.filter(state=Evaluation.State.EVALUATED)
if evaluation.textanswer_review_state == Evaluation.TextAnswerReviewState.REVIEW_URGENT
]
if not evaluations:
evaluation_url_tuples = get_sorted_evaluation_url_tuples_with_urgent_review()
if not evaluation_url_tuples:
logger.info("no evaluations require a reminder about text answer review.")
return
evaluations = sorted(evaluations, key=lambda evaluation: evaluation.full_name)

for manager in Group.objects.get(name="Manager").user_set.all():
EmailTemplate.send_textanswer_reminder_to_user(manager, evaluations)
EmailTemplate.send_textanswer_reminder_to_user(manager, evaluation_url_tuples)

logger.info("sent text answer review reminders.")
4 changes: 2 additions & 2 deletions evap/evaluation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1995,7 +1995,7 @@ def send_participant_publish_notifications(cls, evaluations, template=None):
template.send_to_user(participant, {}, body_params, use_cc=True)

@classmethod
def send_textanswer_reminder_to_user(cls, user: UserProfile, evaluations: List[Evaluation]):
body_params = {"user": user, "evaluations": evaluations}
def send_textanswer_reminder_to_user(cls, user: UserProfile, evaluation_url_tuples: List[Tuple[Evaluation, str]]):
body_params = {"user": user, "evaluation_url_tuples": evaluation_url_tuples}
template = cls.objects.get(name=cls.TEXT_ANSWER_REVIEW_REMINDER)
template.send_to_user(user, {}, body_params, use_cc=False)
9 changes: 9 additions & 0 deletions evap/evaluation/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,15 @@ def test_send_text_answer_review_reminder(self):
management.call_command("send_reminders")

self.assertEqual(mock.call_count, 1)
self.assertEqual(
mock.call_args_list[0][0][2].get("evaluation_url_tuples"),
[
(
evaluation,
f"{settings.PAGE_URL}/staff/semester/{evaluation.course.semester.id}/evaluation/{evaluation.id}/textanswers",
)
],
)


class TestLintCommand(TestCase):
Expand Down
Loading

0 comments on commit f44d9d5

Please sign in to comment.