From e120eca78ccbd7b829707f6a1691d2cb6625c8c6 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Sun, 14 Mar 2021 17:08:33 +0100 Subject: [PATCH] [Lesson overview] Use template engine for notification body --- aleksis/apps/alsijil/actions.py | 11 ++++------- .../templates/alsijil/notifications/check.html | 4 ++++ 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 aleksis/apps/alsijil/templates/alsijil/notifications/check.html diff --git a/aleksis/apps/alsijil/actions.py b/aleksis/apps/alsijil/actions.py index d4fca3ba2..14870259c 100644 --- a/aleksis/apps/alsijil/actions.py +++ b/aleksis/apps/alsijil/actions.py @@ -3,6 +3,7 @@ from typing import Sequence from django.contrib import messages from django.contrib.humanize.templatetags.humanize import apnumber from django.http import HttpRequest +from django.template.loader import get_template from django.urls import reverse from django.utils.translation import gettext_lazy as _ @@ -22,17 +23,13 @@ def send_request_to_check_entry(modeladmin, request: HttpRequest, selected_items grouped_by_teachers.setdefault(teacher, []) grouped_by_teachers[teacher].append(entry) + template = get_template("alsijil/notifications/check.html") for teacher, items in grouped_by_teachers.items(): + msg = template.render({"items": items}) + title = _( f"{request.user.person.addressing_name} wants you to check some class register entries." ) - msg = _("Please check if the following class register entries are complete and correct:\n") - - # Add one line for each entry to check - for entry in items: - reg_object = entry["register_object"] - date = entry["date"] - msg += f"- {reg_object} ({date})\n" n = Notification( title=title, diff --git a/aleksis/apps/alsijil/templates/alsijil/notifications/check.html b/aleksis/apps/alsijil/templates/alsijil/notifications/check.html new file mode 100644 index 000000000..d76a1a0a5 --- /dev/null +++ b/aleksis/apps/alsijil/templates/alsijil/notifications/check.html @@ -0,0 +1,4 @@ +{% load i18n %}{% trans "Please check if the following class register entries are complete and correct:" %} +{% for entry in items %} +- {{ entry.register_object }} ({{ entry.date }}) +{% endfor %} \ No newline at end of file -- GitLab