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

Grade Publishing Reminder Email in send_reminders #2284

Merged
merged 18 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
10 changes: 10 additions & 0 deletions evap/development/fixtures/test_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -133247,6 +133247,16 @@
"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>"
}
},
{
"model": "evaluation.emailtemplate",
"pk": 10,
"fields": {
"name": "Grade Reminder",
"subject": "[EvaP] Notenveröffentlichung für {{semester.name_de}} / Grade publishing for {{semester.name_en}}",
"plain_content": "(English version below)\r\n\r\nLiebes Studienreferat,\r\n\r\nfür die folgenden Veranstaltungen im {{semester.name_de}} wurden bisher keine Notendokumente auf EvaP hochgeladen. Bitte prüfen Sie, ob die Noten bereits vorliegen und die Evaluierungsergebnisse veröffentlicht werden können.\r\n\r\n{% for responsible, courses in responsibles_and_courses_without_final_grades %}\r\n{{ responsible }}\r\n{% for course in courses %}\r\n- {{ course.name_de }} ({{ course.type }})\r\n{% endfor %}\r\n\r\n{% endfor %}\r\n\r\nBei Fragen und Rückmeldungen können Sie sich jederzeit gerne an das Evaluierungsteam wenden ({{ contact_email }}).\r\n\r\nFreundliche Grüße,\r\ndas Evaluierungsteam\r\n\r\n(Dies ist eine automatisch versendete E-Mail.)\r\n\r\n\r\n--\r\n\r\n\r\nDear office for student affairs,\r\n\r\nfor the following courses in {{semester.name_en}}, no grade documents have yet been uploaded on EvaP. Please check whether the grades are already available and whether the evaluation results can be published.\r\n\r\n{% for responsible, courses in responsibles_and_courses_without_final_grades %}\r\n{{ responsible }}\r\n{% for course in courses %}\r\n- {{ course.name_en }} ({{ course.type }})\r\n{% endfor %}\r\n\r\n{% endfor %}\r\n\r\nIf you have any questions or feedback, please contact the evaluation team ({{ contact_email }}).\r\n\r\nKind regards,\r\nthe Evaluation Team\r\n\r\n(This is an automated message.)",
richardebeling marked this conversation as resolved.
Show resolved Hide resolved
"html_content": "<i>(English version below)</i><br /><br /><br />\r\n\r\nLiebes Studienreferat,<br /><br />\r\n\r\nfür die folgenden Veranstaltungen im {{semester.name_de}} wurden bisher keine Notendokumente auf EvaP hochgeladen. Bitte prüfen Sie, ob die Noten bereits vorliegen und die Evaluierungsergebnisse veröffentlicht werden können.<br /><br />\r\n\r\n{% for responsible, courses in responsibles_and_courses_without_final_grades %}\r\n{{ responsible }}\r\n<ul>\r\n{% for course in courses %}\r\n<li>{{ course.name_de }} ({{ course.type }})</li>\r\n{% endfor %}\r\n</ul><br/>\r\n{% endfor %}\r\n\r\nBei Fragen und Rückmeldungen können Sie sich jederzeit gerne an das Evaluierungsteam wenden (<a href=\"mailto:{{ contact_email }}\">{{ contact_email }}</a>).<br /><br />\r\n\r\nFreundliche Grüße,<br />\r\ndas Evaluierungsteam<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 office for student affairs,<br /><br />\r\n\r\nfor the following courses in {{semester.name_en}}, no grade documents have yet been uploaded on EvaP. Please check whether the grades are already available and whether the evaluation results can be published.<br /><br />\r\n\r\n{% for responsible, courses in responsibles_and_courses_without_final_grades %}\r\n{{ responsible }}\r\n<ul>\r\n{% for course in courses %}\r\n<li>{{ course.name_en }} ({{ course.type }})</li>\r\n{% endfor %}\r\n</ul><br/>\r\n{% endfor %}\r\n\r\nIf you have any questions or feedback, please contact the evaluation team (<a href=\"mailto:{{ contact_email }}\">{{ contact_email }}</a>).<br /><br />\r\n\r\nKind regards,<br />\r\nthe Evaluation Team<br /><br />\r\n\r\n<i>(This is an automated message.)</i>"
}
},
{
"model": "evaluation.votetimestamp",
"pk": 1,
Expand Down
46 changes: 45 additions & 1 deletion evap/evaluation/management/commands/send_reminders.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
from django.conf import settings
from django.contrib.auth.models import Group
from django.core.management.base import BaseCommand
from django.db.models import Exists, OuterRef, Prefetch
from django.urls import reverse

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

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -36,6 +38,7 @@ def handle(self, *args, **options):
logger.info("send_reminders called.")
self.send_student_reminders()
self.send_textanswer_reminders()
self.send_grade_reminders()
logger.info("send_reminders finished.")

@staticmethod
Expand Down Expand Up @@ -74,3 +77,44 @@ def send_textanswer_reminders():
EmailTemplate.send_textanswer_reminder_to_user(manager, evaluation_url_tuples)

logger.info("sent text answer review reminders.")

@staticmethod
def send_grade_reminders():
def should_remind_today():
normalized_reminder_dates = {
datetime.date(1000, d.month, d.day) for d in settings.GRADE_REMINDER_EMAIL_DATES
}
today = datetime.date.today()
normalized_today = datetime.date(1000, today.month, today.day)

return normalized_today in normalized_reminder_dates

if not should_remind_today():
return

courses_without_final_grades = Course.objects_with_missing_final_grades().order_by("name_en")
semesters = (
Semester.objects.filter(grade_documents_are_deleted=False)
.filter(Exists(courses_without_final_grades.filter(semester__pk=OuterRef("pk"))))
.prefetch_related(
Prefetch("courses", queryset=courses_without_final_grades, to_attr="courses_without_final_grades"),
)
)

for semester in semesters:
responsibles_and_courses_without_final_grades = unordered_groupby(
(responsible, course)
for course in semester.courses_without_final_grades
for responsible in course.responsibles.all()
)

for recipient in settings.GRADE_REMINDER_EMAIL_RECIPIENTS:
EmailTemplate.send_grade_reminder(
recipient, semester, responsibles_and_courses_without_final_grades.items()
)

logger.info(
"sent grade document reminders for %d semesters to %d people.",
len(semesters),
len(settings.GRADE_REMINDER_EMAIL_RECIPIENTS),
)
31 changes: 31 additions & 0 deletions evap/evaluation/migrations/0145_grade_reminder_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django.db import migrations


emailtemplates = [
("Grade Reminder", "[EvaP] Notenveröffentlichung für {{semester.name_de}} / Grade publishing for {{semester.name_en}}"),
]


def insert_emailtemplates(apps, _schema_editor):
EmailTemplate = apps.get_model("evaluation", "EmailTemplate")

for name, subject in emailtemplates:
EmailTemplate.objects.create(name=name, subject=subject, plain_content="", html_content="")


def remove_emailtemplates(apps, _schema_editor):
EmailTemplate = apps.get_model("evaluation", "EmailTemplate")

for name, __ in emailtemplates:
EmailTemplate.objects.filter(name=name).delete()


class Migration(migrations.Migration):

dependencies = [
('evaluation', '0144_alter_evaluation_state'),
]

operations = [
migrations.RunPython(insert_emailtemplates, reverse_code=remove_emailtemplates),
]
Loading
Loading