From 551b5ed6be389a89e1c7cd9ccb25af8f2f2ba6ec Mon Sep 17 00:00:00 2001 From: moanos Date: Sat, 12 Jul 2025 09:17:58 +0200 Subject: [PATCH] feat: add plaintext versions of the e-mail --- src/fellchensammlung/mail.py | 11 +++++++++-- src/fellchensammlung/models.py | 3 +++ .../templates/fellchensammlung/mail/base.txt | 4 ++++ .../templates/fellchensammlung/mail/footer.txt | 1 + .../mail/notifications/an-deactivated.txt | 7 +++++++ .../mail/notifications/an-for-search-found.txt | 9 +++++++++ .../mail/notifications/an-to-be-checked.txt | 8 ++++++++ .../mail/notifications/new-comment.txt | 11 +++++++++++ .../mail/notifications/new-user.html | 2 +- .../fellchensammlung/mail/notifications/new-user.txt | 12 ++++++++++++ .../fellchensammlung/mail/notifications/report.txt | 11 +++++++++++ 11 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 src/fellchensammlung/templates/fellchensammlung/mail/base.txt create mode 100644 src/fellchensammlung/templates/fellchensammlung/mail/footer.txt create mode 100644 src/fellchensammlung/templates/fellchensammlung/mail/notifications/an-deactivated.txt create mode 100644 src/fellchensammlung/templates/fellchensammlung/mail/notifications/an-for-search-found.txt create mode 100644 src/fellchensammlung/templates/fellchensammlung/mail/notifications/an-to-be-checked.txt create mode 100644 src/fellchensammlung/templates/fellchensammlung/mail/notifications/new-comment.txt create mode 100644 src/fellchensammlung/templates/fellchensammlung/mail/notifications/new-user.txt create mode 100644 src/fellchensammlung/templates/fellchensammlung/mail/notifications/report.txt diff --git a/src/fellchensammlung/mail.py b/src/fellchensammlung/mail.py index 2421787..e80c1d6 100644 --- a/src/fellchensammlung/mail.py +++ b/src/fellchensammlung/mail.py @@ -23,7 +23,7 @@ def mail_admins_new_report(report): subject = _("Neue Meldung") html_message = render_to_string('fellchensammlung/mail/notifications/report.html', context) - plain_message = strip_tags(html_message) + plain_message = render_to_string('fellchensammlung/mail/notifications/report.txt', context) mail.send_mail(subject, plain_message, @@ -41,20 +41,27 @@ def send_notification_email(notification_pk): context["user_comment"] = notification.report.user_comment context["report_url"] = f"{base_url}{notification.report.get_absolute_url()}" html_message = render_to_string('fellchensammlung/mail/notifications/report.html', context) + plain_message = render_to_string('fellchensammlung/mail/notifications/report.txt', context) elif notification.notification_type == NotificationTypeChoices.NEW_USER: html_message = render_to_string('fellchensammlung/mail/notifications/new-user.html', context) + plain_message = render_to_string('fellchensammlung/mail/notifications/new-user.txt', context) elif notification.notification_type == NotificationTypeChoices.AN_IS_TO_BE_CHECKED: html_message = render_to_string('fellchensammlung/mail/notifications/an-to-be-checked.html', context) + plain_message = render_to_string('fellchensammlung/mail/notifications/an-to-be-checked.txt', context) elif notification.notification_type == NotificationTypeChoices.AN_WAS_DEACTIVATED: html_message = render_to_string('fellchensammlung/mail/notifications/an-deactivated.html', context) + plain_message = render_to_string('fellchensammlung/mail/notifications/an-deactivated.txt', context) elif notification.notification_type == NotificationTypeChoices.AN_FOR_SEARCH_FOUND: html_message = render_to_string('fellchensammlung/mail/notifications/an-for-search-found.html', context) + plain_message = render_to_string('fellchensammlung/mail/notifications/an-for-search-found.txt', context) elif notification.notification_type == NotificationTypeChoices.NEW_COMMENT: html_message = render_to_string('fellchensammlung/mail/notifications/new-comment.html', context) + plain_message = render_to_string('fellchensammlung/mail/notifications/new-comment.txt', context) else: raise NotImplementedError("Unknown notification type") - plain_message = strip_tags(html_message) + if "plain_message" not in locals(): + plain_message = strip_tags(html_message) mail.send_mail(subject, plain_message, settings.DEFAULT_FROM_EMAIL, [notification.user_to_notify.email], html_message=html_message) diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index 15bd6af..b5822bc 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -252,6 +252,9 @@ class User(AbstractUser): def get_absolute_url(self): return reverse("user-detail", args=[str(self.pk)]) + def get_full_url(self): + return f"{base_url}{self.get_absolute_url()}" + def get_notifications_url(self): return self.get_absolute_url() diff --git a/src/fellchensammlung/templates/fellchensammlung/mail/base.txt b/src/fellchensammlung/templates/fellchensammlung/mail/base.txt new file mode 100644 index 0000000..2efc2d4 --- /dev/null +++ b/src/fellchensammlung/templates/fellchensammlung/mail/base.txt @@ -0,0 +1,4 @@ +{% block content %}{% endblock %} + +--- +{% include "fellchensammlung/mail/footer.txt" %} \ No newline at end of file diff --git a/src/fellchensammlung/templates/fellchensammlung/mail/footer.txt b/src/fellchensammlung/templates/fellchensammlung/mail/footer.txt new file mode 100644 index 0000000..3197e57 --- /dev/null +++ b/src/fellchensammlung/templates/fellchensammlung/mail/footer.txt @@ -0,0 +1 @@ +🐀 notfellchen.org | Für Menschen die Ratten aus dem Tierschutz ein liebendes Zuhause geben wollen. diff --git a/src/fellchensammlung/templates/fellchensammlung/mail/notifications/an-deactivated.txt b/src/fellchensammlung/templates/fellchensammlung/mail/notifications/an-deactivated.txt new file mode 100644 index 0000000..5b8d944 --- /dev/null +++ b/src/fellchensammlung/templates/fellchensammlung/mail/notifications/an-deactivated.txt @@ -0,0 +1,7 @@ +{% extends "fellchensammlung/mail/base.txt" %} +{% load i18n %} +{% block content %}{% blocktranslate %}Moin, +die Vermittlung {{ notification.adoption_notice }} wurde deaktiviert. +{% endblocktranslate %} + +{% translate 'Vermittlung anzeigen' %}: {{ notification.adoption_notice.get_full_url }}{% endblock %} \ No newline at end of file diff --git a/src/fellchensammlung/templates/fellchensammlung/mail/notifications/an-for-search-found.txt b/src/fellchensammlung/templates/fellchensammlung/mail/notifications/an-for-search-found.txt new file mode 100644 index 0000000..9b72cb5 --- /dev/null +++ b/src/fellchensammlung/templates/fellchensammlung/mail/notifications/an-for-search-found.txt @@ -0,0 +1,9 @@ +{% extends "fellchensammlung/mail/base.txt" %} +{% load i18n %} +{% block content %}{% blocktranslate %}Moin, + +es wurde eine neue Vermittlung gefunden, die deinen Kriterien entspricht: {{ notification.adoption_notice }} + + +Vermittlung anzeigen: {{ notification.adoption_notice.get_full_url }} +{% endblocktranslate %}{% endblock %} \ No newline at end of file diff --git a/src/fellchensammlung/templates/fellchensammlung/mail/notifications/an-to-be-checked.txt b/src/fellchensammlung/templates/fellchensammlung/mail/notifications/an-to-be-checked.txt new file mode 100644 index 0000000..386870d --- /dev/null +++ b/src/fellchensammlung/templates/fellchensammlung/mail/notifications/an-to-be-checked.txt @@ -0,0 +1,8 @@ +{% extends "fellchensammlung/mail/base.txt" %} +{% load i18n %} +{% block content %}{% blocktranslate %}Moin, + +die Vermittlung {{ notification.adoption_notice }} muss überprüft werden. + +Vermittlung anzeigen: {{ notification.adoption_notice.get_full_url }} +{% endblocktranslate %}{% endblock %} \ No newline at end of file diff --git a/src/fellchensammlung/templates/fellchensammlung/mail/notifications/new-comment.txt b/src/fellchensammlung/templates/fellchensammlung/mail/notifications/new-comment.txt new file mode 100644 index 0000000..4d03874 --- /dev/null +++ b/src/fellchensammlung/templates/fellchensammlung/mail/notifications/new-comment.txt @@ -0,0 +1,11 @@ +{% extends "fellchensammlung/mail/base.html" %} +{% load i18n %} +{% load custom_tags %} +{% block content %}{% blocktranslate %}Moin, + +folgender Kommentar wurde zur Vermittlung {{ notification.adoption_notice }} hinzugefügt: + +{{ notification.comment.text }} + +Vermittlung anzeigen: {{ notification.adoption_notice.get_full_url }} +{% endblocktranslate %}{% endblock %} \ No newline at end of file diff --git a/src/fellchensammlung/templates/fellchensammlung/mail/notifications/new-user.html b/src/fellchensammlung/templates/fellchensammlung/mail/notifications/new-user.html index 3bffbac..35441be 100644 --- a/src/fellchensammlung/templates/fellchensammlung/mail/notifications/new-user.html +++ b/src/fellchensammlung/templates/fellchensammlung/mail/notifications/new-user.html @@ -14,6 +14,6 @@ Details findest du hier

- {% translate 'User anzeigen' %} + {% translate 'User anzeigen' %}

{% endblock %} \ No newline at end of file diff --git a/src/fellchensammlung/templates/fellchensammlung/mail/notifications/new-user.txt b/src/fellchensammlung/templates/fellchensammlung/mail/notifications/new-user.txt new file mode 100644 index 0000000..616cb79 --- /dev/null +++ b/src/fellchensammlung/templates/fellchensammlung/mail/notifications/new-user.txt @@ -0,0 +1,12 @@ +{% extends "fellchensammlung/mail/base.txt" %} +{% load i18n %} +{% block content %}{% blocktranslate %}Moin, + +es wurde ein neuer Useraccount erstellt. + +{{ notification }} +Related: {{ notification.user_related }} +{{ notification.user_related.get_full_url }} + +User anzeigen: {{ notification.user_related.get_full_url }} +{% endblocktranslate %}{% endblock %} \ No newline at end of file diff --git a/src/fellchensammlung/templates/fellchensammlung/mail/notifications/report.txt b/src/fellchensammlung/templates/fellchensammlung/mail/notifications/report.txt new file mode 100644 index 0000000..b0ebce8 --- /dev/null +++ b/src/fellchensammlung/templates/fellchensammlung/mail/notifications/report.txt @@ -0,0 +1,11 @@ +{% extends "fellchensammlung/mail/base.txt" %} +{% load i18n %} +{% block content %}{% blocktranslate %}Moin, + +es gibt eine neue Meldung. Folgende Nachricht wurde zur Meldung hinzugefügt: + +{{ user_comment }} + +Bitte bearbeite die Meldung möglichst bald. + +Meldung bearbeiten: {{ report_url }}{% endblocktranslate %}{% endblock %} \ No newline at end of file