From 037e4ae6e8559519d6621faafa61589127e12e48 Mon Sep 17 00:00:00 2001 From: Ojakoo Date: Fri, 23 Sep 2022 20:30:08 +0300 Subject: [PATCH 1/2] Use html templates for kaehmy emails. No translations for now. --- kaehmy/views.py | 22 ++++++++++++---------- templates/kaehmy/email_comment.html | 10 ++++++++++ templates/kaehmy/email_kaehmy.html | 13 +++++++++++++ 3 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 templates/kaehmy/email_comment.html create mode 100644 templates/kaehmy/email_kaehmy.html diff --git a/kaehmy/views.py b/kaehmy/views.py index 1020936..3fcfefb 100644 --- a/kaehmy/views.py +++ b/kaehmy/views.py @@ -4,6 +4,7 @@ from django.views.decorators.http import require_http_methods from django.views.decorators.csrf import ensure_csrf_cookie from django.http import HttpResponseRedirect from django.contrib.auth.decorators import login_required +from django.template.loader import render_to_string import logging from sikweb.settings import URL @@ -64,14 +65,16 @@ def comment(request, *args, **kwargs): if form.is_valid(): comment = form.save() name = comment.name + url = f"https://{URL}/kaehmy" to_email = comment.parent.email subject = "Kaehmyysi tai kommenttiisi on vastattu!" - email_body = ( - f"{name.capitalize()} on vastannut kaehmyhakemukseesi tai kommenttiisi kaehmypalvelussa.\r\n\r\n" - "Käy lukemassa viesti osoitteessa https://{URL}/kaehmy" + message = render_to_string( + "kaehmy/email_comment.html", + { "name": name, "url": url } ) - send_email(to=to_email, subject=subject, body=email_body) + + send_email(to=to_email, subject=subject, body=message, html=True) logging.debug(f"Sent kaehmy comment email to recipient <{to_email}>") return redirect("/kaehmy") @@ -129,16 +132,15 @@ def submit(request, *args, **kwargs): url = f"https://{URL}/kaehmy" name = form.cleaned_data.get("name", "Anonymous") - email_body = ( - f"Moikka {name}!\r\n\r\nHienoa, että kilta kiinnostaa! Kaehmysi on vastaanotettu.\r\n" - "Mahdollisista kommenteista tulee ilmoitus sähköpostitse.\r\n\r\n" - "Käy katsomassa kaehmytilanne osoitteessa {url}" - ) to_email = form.cleaned_data.get("email", "") subject = "Arwokas kirjattu kirje mahdolliselle tulewalle kiltahenkilölle" + message = render_to_string( + "kaehmy/email_kaehmy.html", + { "name": name, "url": url } + ) - send_email(to_email, subject, email_body) + send_email(to=to_email, subject=subject, body=message, html=True) logging.debug(f"Sent kaehmy email to recipient <{to_email}>") processHooks(message=f"Uusi New kaehmy! {name} -> {url}", eventType="kaehmy") diff --git a/templates/kaehmy/email_comment.html b/templates/kaehmy/email_comment.html new file mode 100644 index 0000000..51580ac --- /dev/null +++ b/templates/kaehmy/email_comment.html @@ -0,0 +1,10 @@ +{% load i18n %} + +

+ Hei! +

+

+ {{ name }} on vastannut kaehmyhakemukseesi tai kommenttiisi kaehmypalvelussa. + Käy lukemassa viesti + täältä. +

\ No newline at end of file diff --git a/templates/kaehmy/email_kaehmy.html b/templates/kaehmy/email_kaehmy.html new file mode 100644 index 0000000..3b7fb69 --- /dev/null +++ b/templates/kaehmy/email_kaehmy.html @@ -0,0 +1,13 @@ +{% load i18n %} + +

+ Moikka {{ name }}! +

+

+ Hienoa, että kilta kiinnostaa! Kaehmysi on vastaanotettu. + Mahdollisista kommenteista tulee ilmoitus sähköpostitse. +

+

+ Käy katsomassa kaehmytilanne + täältä. +

\ No newline at end of file From 70676d5203f41d7cbbe666e75a23e323aed35b10 Mon Sep 17 00:00:00 2001 From: Ojakoo Date: Fri, 23 Sep 2022 20:53:25 +0300 Subject: [PATCH 2/2] Lint --- kaehmy/views.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kaehmy/views.py b/kaehmy/views.py index 3fcfefb..99430db 100644 --- a/kaehmy/views.py +++ b/kaehmy/views.py @@ -70,8 +70,7 @@ def comment(request, *args, **kwargs): to_email = comment.parent.email subject = "Kaehmyysi tai kommenttiisi on vastattu!" message = render_to_string( - "kaehmy/email_comment.html", - { "name": name, "url": url } + "kaehmy/email_comment.html", {"name": name, "url": url} ) send_email(to=to_email, subject=subject, body=message, html=True) @@ -136,8 +135,7 @@ def submit(request, *args, **kwargs): to_email = form.cleaned_data.get("email", "") subject = "Arwokas kirjattu kirje mahdolliselle tulewalle kiltahenkilölle" message = render_to_string( - "kaehmy/email_kaehmy.html", - { "name": name, "url": url } + "kaehmy/email_kaehmy.html", {"name": name, "url": url} ) send_email(to=to_email, subject=subject, body=message, html=True)