diff --git a/kaehmy/views.py b/kaehmy/views.py index 1020936..99430db 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,15 @@ 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 +131,14 @@ 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