From f59bdb39fad7df6668f834d25ad2f5c178bc2271 Mon Sep 17 00:00:00 2001 From: Kara Engelhardt Date: Mon, 4 Mar 2024 15:01:41 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Allow=20setting=20reminder=20text?= =?UTF-8?q?=20from=20foilaw?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- froide/foirequest/forms/message.py | 38 +++++++++++++------ .../foirequest/emails/overdue_reply.txt | 5 +-- .../emails/overdue_reply_footer.txt | 4 ++ .../0046_foilawtranslation_overdue_reply.py | 17 +++++++++ froide/publicbody/models.py | 1 + 5 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 froide/foirequest/templates/foirequest/emails/overdue_reply_footer.txt create mode 100644 froide/publicbody/migrations/0046_foilawtranslation_overdue_reply.py diff --git a/froide/foirequest/forms/message.py b/froide/foirequest/forms/message.py index c765ef980..6be9b144e 100644 --- a/froide/foirequest/forms/message.py +++ b/froide/foirequest/forms/message.py @@ -7,6 +7,7 @@ from django import forms from django.conf import settings from django.db import transaction +from django.template import Context, Template from django.template.loader import render_to_string from django.utils import timezone from django.utils.translation import gettext_lazy as _ @@ -122,17 +123,32 @@ def get_send_message_form(*args, **kwargs): if foirequest.is_overdue() and foirequest.awaits_response(): days = (timezone.now() - foirequest.due_date).days + 1 first_message = foirequest.messages[0] - message = render_to_string( - select_foirequest_template( - foirequest, "foirequest/emails/overdue_reply.txt" - ), - { - "due": ngettext_lazy("%(count)s day", "%(count)s days", days) - % {"count": days}, - "foirequest": foirequest, - "first_message": first_message, - }, - ) + + context = { + "due": ngettext_lazy("%(count)s day", "%(count)s days", days) + % {"count": days}, + "foirequest": foirequest, + "first_message": first_message, + } + + message = None + + if foirequest.law.overdue_reply: + template_str = "{top}{body}{bottom}{footer}".format( + top="{% autoescape off %}", + body=foirequest.law.overdue_reply, + bottom="{% endautoescape %}", + footer='\r\n{% include "foirequest/emails/overdue_reply_footer.txt" %}', + ) + message = Template(template_str).render(Context(context)) + if not message: + message = render_to_string( + select_foirequest_template( + foirequest, "foirequest/emails/overdue_reply.txt" + ), + context, + ) + else: message = get_default_initial_message(foirequest.user) diff --git a/froide/foirequest/templates/foirequest/emails/overdue_reply.txt b/froide/foirequest/templates/foirequest/emails/overdue_reply.txt index 718f867ba..83278162b 100644 --- a/froide/foirequest/templates/foirequest/emails/overdue_reply.txt +++ b/froide/foirequest/templates/foirequest/emails/overdue_reply.txt @@ -5,6 +5,5 @@ Please update me on the status of my request as soon as possible. Sincerely yours, {{ name }}{% endblocktrans %} - -{% translate "-------- Forwarded Message --------" %} -{{ first_message.get_quoted_message }}{% endautoescape %} +{% endautoescape %} +{% include "foirequest/emails/overdue_reply_footer.txt" %} diff --git a/froide/foirequest/templates/foirequest/emails/overdue_reply_footer.txt b/froide/foirequest/templates/foirequest/emails/overdue_reply_footer.txt new file mode 100644 index 000000000..05f46eb65 --- /dev/null +++ b/froide/foirequest/templates/foirequest/emails/overdue_reply_footer.txt @@ -0,0 +1,4 @@ +{% load i18n %}{% autoescape off%} +{% translate "-------- Forwarded Message --------" %} +{{ first_message.get_quoted_message }} +{% endautoescape %} diff --git a/froide/publicbody/migrations/0046_foilawtranslation_overdue_reply.py b/froide/publicbody/migrations/0046_foilawtranslation_overdue_reply.py new file mode 100644 index 000000000..33920293c --- /dev/null +++ b/froide/publicbody/migrations/0046_foilawtranslation_overdue_reply.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.4 on 2024-03-04 13:28 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("publicbody", "0045_jurisdiction_last_modified_at"), + ] + + operations = [ + migrations.AddField( + model_name="foilawtranslation", + name="overdue_reply", + field=models.TextField(blank=True, verbose_name="overdue reply"), + ), + ] diff --git a/froide/publicbody/models.py b/froide/publicbody/models.py index 1f96d50b9..753e90e4b 100644 --- a/froide/publicbody/models.py +++ b/froide/publicbody/models.py @@ -117,6 +117,7 @@ class FoiLaw(TranslatableModel): letter_start=models.TextField(_("Start of Letter"), blank=True), letter_end=models.TextField(_("End of Letter"), blank=True), refusal_reasons=models.TextField(_("refusal reasons"), blank=True), + overdue_reply=models.TextField(_("overdue reply"), blank=True), ) created = models.DateField(_("Creation Date"), blank=True, null=True)