feat: Add notification partials including new mapping system for templates
This commit is contained in:
@@ -17,6 +17,8 @@ from .tools import misc, geo
|
|||||||
from notfellchen.settings import MEDIA_URL, base_url
|
from notfellchen.settings import MEDIA_URL, base_url
|
||||||
from .tools.geo import LocationProxy, Position
|
from .tools.geo import LocationProxy, Position
|
||||||
from .tools.misc import age_as_hr_string, time_since_as_hr_string
|
from .tools.misc import age_as_hr_string, time_since_as_hr_string
|
||||||
|
from .tools.model_helpers import NotificationTypeChoices
|
||||||
|
from .tools.model_helpers import ndm as NotificationDisplayMapping
|
||||||
|
|
||||||
|
|
||||||
class Language(models.Model):
|
class Language(models.Model):
|
||||||
@@ -913,16 +915,6 @@ class Comment(models.Model):
|
|||||||
return self.adoption_notice.get_absolute_url()
|
return self.adoption_notice.get_absolute_url()
|
||||||
|
|
||||||
|
|
||||||
class NotificationTypeChoices(models.TextChoices):
|
|
||||||
NEW_USER = "new_user", _("Useraccount wurde erstellt")
|
|
||||||
NEW_REPORT_AN = "new_report_an", _("Vermittlung wurde gemeldet")
|
|
||||||
NEW_REPORT_COMMENT = "new_report_comment", _("Kommentar wurde gemeldet")
|
|
||||||
AN_IS_TO_BE_CHECKED = "an_is_to_be_checked", _("Vermittlung muss überprüft werden")
|
|
||||||
AN_WAS_DEACTIVATED = "an_was_deactivated", _("Vermittlung wurde deaktiviert")
|
|
||||||
AN_FOR_SEARCH_FOUND = "an_for_search_found", _("Vermittlung für Suche gefunden")
|
|
||||||
NEW_COMMENT = "new_comment", _("Neuer Kommentar")
|
|
||||||
|
|
||||||
|
|
||||||
class Notification(models.Model):
|
class Notification(models.Model):
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
updated_at = models.DateTimeField(auto_now=True)
|
updated_at = models.DateTimeField(auto_now=True)
|
||||||
@@ -939,7 +931,8 @@ class Notification(models.Model):
|
|||||||
read = models.BooleanField(default=False)
|
read = models.BooleanField(default=False)
|
||||||
read_at = models.DateTimeField(blank=True, null=True, verbose_name=_("Gelesen am"))
|
read_at = models.DateTimeField(blank=True, null=True, verbose_name=_("Gelesen am"))
|
||||||
comment = models.ForeignKey(Comment, blank=True, null=True, on_delete=models.CASCADE, verbose_name=_('Antwort'))
|
comment = models.ForeignKey(Comment, blank=True, null=True, on_delete=models.CASCADE, verbose_name=_('Antwort'))
|
||||||
adoption_notice = models.ForeignKey(AdoptionNotice, blank=True, null=True, on_delete=models.CASCADE, verbose_name=_('Vermittlung'))
|
adoption_notice = models.ForeignKey(AdoptionNotice, blank=True, null=True, on_delete=models.CASCADE,
|
||||||
|
verbose_name=_('Vermittlung'))
|
||||||
user_related = models.ForeignKey(User,
|
user_related = models.ForeignKey(User,
|
||||||
blank=True, null=True,
|
blank=True, null=True,
|
||||||
on_delete=models.CASCADE, verbose_name=_('Verwandter Useraccount'),
|
on_delete=models.CASCADE, verbose_name=_('Verwandter Useraccount'),
|
||||||
@@ -961,6 +954,9 @@ class Notification(models.Model):
|
|||||||
self.read_at = timezone.now()
|
self.read_at = timezone.now()
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
def get_body_part(self):
|
||||||
|
return NotificationDisplayMapping[self.notification_type].web_partial
|
||||||
|
|
||||||
|
|
||||||
class Subscriptions(models.Model):
|
class Subscriptions(models.Model):
|
||||||
owner = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_('Nutzer*in'))
|
owner = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_('Nutzer*in'))
|
||||||
|
@@ -0,0 +1,5 @@
|
|||||||
|
{% load i18n %}
|
||||||
|
{% blocktranslate with adoption_notice_title=notification.adoption_notice.name %}
|
||||||
|
Die Vermittlung <strong>{{ adoption_notice_title }}</strong> wurde deaktiviert.
|
||||||
|
{% endblocktranslate %}
|
||||||
|
<a href="{{ notification.adoption_notice.get_full_url }}">{% translate 'Vermittlung anzeigen' %}</a>
|
@@ -0,0 +1,5 @@
|
|||||||
|
{% load i18n %}
|
||||||
|
{% blocktranslate %}
|
||||||
|
Es wurde eine neue Vermittlung gefunden, die deinen Kriterien entspricht:
|
||||||
|
{% endblocktranslate %}
|
||||||
|
<a href="{{ notification.adoption_notice.get_full_url }}">{{ notification.adoption_notice.name }}</a>
|
@@ -0,0 +1,5 @@
|
|||||||
|
{% load i18n %}
|
||||||
|
{% blocktranslate with adoption_notice_title=notification.adoption_notice.name %}
|
||||||
|
Die Vermittlung <strong>{{ adoption_notice_title }}</strong> muss überprüft werden.
|
||||||
|
{% endblocktranslate %}
|
||||||
|
<a href="{{ notification.adoption_notice.get_full_url }}">{% translate 'Vermittlung anzeigen' %}</a>
|
@@ -0,0 +1,13 @@
|
|||||||
|
{% load i18n %}
|
||||||
|
{% load custom_tags %}
|
||||||
|
<p>
|
||||||
|
{% blocktranslate with adoption_notice_title=notification.adoption_notice.name %}
|
||||||
|
Folgender Kommentar wurde zur Vermittlung <strong>{{ adoption_notice_title }}</strong> hinzugefügt:
|
||||||
|
{% endblocktranslate %}
|
||||||
|
</p>
|
||||||
|
<p><i>
|
||||||
|
{{ notification.comment.text | render_markdown }}
|
||||||
|
</i></p>
|
||||||
|
<p>
|
||||||
|
<a href="{{ notification.adoption_notice.get_full_url }}">{% translate 'Vermittlung anzeigen' %}</a>
|
||||||
|
</p>
|
@@ -0,0 +1,13 @@
|
|||||||
|
{% load i18n %}
|
||||||
|
<p>
|
||||||
|
{% blocktranslate %}
|
||||||
|
Es gibt eine neue Meldung. Folgende Nachricht wurde zur Meldung hinzugefügt:
|
||||||
|
{% endblocktranslate %}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<i>
|
||||||
|
{{ notification.report.user_comment }}
|
||||||
|
</i>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<a href="{{ notification.report.get_absolute_url }}">{% translate 'Meldung anzeigen' %}</a>
|
@@ -0,0 +1,5 @@
|
|||||||
|
{% load i18n %}
|
||||||
|
{% blocktranslate %}
|
||||||
|
Es wurde ein neuer Useraccount erstellt:
|
||||||
|
{% endblocktranslate %}
|
||||||
|
<a href="{{ notification.user_related.get_full_url }}">{% translate 'User anzeigen' %}</a>
|
@@ -12,6 +12,6 @@
|
|||||||
<i class="card-timestamp">{{ notification.created_at|time_since_hr }}</i>
|
<i class="card-timestamp">{{ notification.created_at|time_since_hr }}</i>
|
||||||
</div>
|
</div>
|
||||||
<div class="notification-body">
|
<div class="notification-body">
|
||||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
{% include notification.get_body_part %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
57
src/fellchensammlung/tools/model_helpers.py
Normal file
57
src/fellchensammlung/tools/model_helpers.py
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
"""
|
||||||
|
Helpers that MUST NOT DEPEND ON MODELS to avoid circular imports
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class NotificationTypeChoices(models.TextChoices):
|
||||||
|
NEW_USER = "new_user", _("Useraccount wurde erstellt")
|
||||||
|
NEW_REPORT_AN = "new_report_an", _("Vermittlung wurde gemeldet")
|
||||||
|
NEW_REPORT_COMMENT = "new_report_comment", _("Kommentar wurde gemeldet")
|
||||||
|
AN_IS_TO_BE_CHECKED = "an_is_to_be_checked", _("Vermittlung muss überprüft werden")
|
||||||
|
AN_WAS_DEACTIVATED = "an_was_deactivated", _("Vermittlung wurde deaktiviert")
|
||||||
|
AN_FOR_SEARCH_FOUND = "an_for_search_found", _("Vermittlung für Suche gefunden")
|
||||||
|
NEW_COMMENT = "new_comment", _("Neuer Kommentar")
|
||||||
|
|
||||||
|
|
||||||
|
class NotificationDisplayMapping:
|
||||||
|
def __init__(self, email_html_template, email_plain_template, web_partial):
|
||||||
|
self.email_html_template = email_html_template
|
||||||
|
self.email_plain_template = email_plain_template
|
||||||
|
self.web_partial = web_partial
|
||||||
|
|
||||||
|
|
||||||
|
report_mapping = NotificationDisplayMapping(
|
||||||
|
email_html_template='fellchensammlung/mail/notifications/report.html',
|
||||||
|
email_plain_template='fellchensammlung/mail/notifications/report.txt',
|
||||||
|
web_partial="fellchensammlung/partials/notifications/body-new-report.html"
|
||||||
|
)
|
||||||
|
# ndm = notification display mapping
|
||||||
|
ndm = {NotificationTypeChoices.NEW_USER: NotificationDisplayMapping(
|
||||||
|
email_html_template='fellchensammlung/mail/notifications/report.html',
|
||||||
|
email_plain_template="fellchensammlung/mail/notifications/report.txt",
|
||||||
|
web_partial="fellchensammlung/partials/notifications/body-new-user.html"),
|
||||||
|
NotificationTypeChoices.NEW_COMMENT: NotificationDisplayMapping(
|
||||||
|
email_html_template='fellchensammlung/mail/notifications/new-comment.html',
|
||||||
|
email_plain_template='fellchensammlung/mail/notifications/new-comment.txt',
|
||||||
|
web_partial="fellchensammlung/partials/notifications/body-new-comment.html"),
|
||||||
|
NotificationTypeChoices.NEW_REPORT_AN: report_mapping,
|
||||||
|
NotificationTypeChoices.NEW_REPORT_COMMENT: report_mapping,
|
||||||
|
NotificationTypeChoices.AN_IS_TO_BE_CHECKED: NotificationDisplayMapping(
|
||||||
|
email_html_template='fellchensammlung/mail/notifications/an-to-be-checked.html',
|
||||||
|
email_plain_template='fellchensammlung/mail/notifications/an-to-be-checked.txt',
|
||||||
|
web_partial='fellchensammlung/partials/notifications/body-an-to-be-checked.html'
|
||||||
|
),
|
||||||
|
NotificationTypeChoices.AN_WAS_DEACTIVATED: NotificationDisplayMapping(
|
||||||
|
email_html_template='fellchensammlung/mail/notifications/an-deactivated.html',
|
||||||
|
email_plain_template='fellchensammlung/mail/notifications/an-deactivated.txt',
|
||||||
|
web_partial='fellchensammlung/partials/notifications/body-an-deactivated.html'
|
||||||
|
),
|
||||||
|
NotificationTypeChoices.AN_FOR_SEARCH_FOUND: NotificationDisplayMapping(
|
||||||
|
email_html_template='fellchensammlung/mail/notifications/an-for-search-found.html',
|
||||||
|
email_plain_template='fellchensammlung/mail/notifications/an-for-search-found.txt',
|
||||||
|
web_partial='fellchensammlung/partials/notifications/body-an-for-search.html'
|
||||||
|
)
|
||||||
|
}
|
@@ -1,4 +1,9 @@
|
|||||||
from fellchensammlung.models import User, Notification, TrustLevel, NotificationTypeChoices
|
from types import SimpleNamespace as sn
|
||||||
|
|
||||||
|
from celery.bin.celery import report
|
||||||
|
|
||||||
|
from fellchensammlung.models import User, Notification, TrustLevel
|
||||||
|
from fellchensammlung.models import NotificationTypeChoices as ntc
|
||||||
|
|
||||||
|
|
||||||
def notify_of_AN_to_be_checked(adoption_notice):
|
def notify_of_AN_to_be_checked(adoption_notice):
|
||||||
@@ -8,7 +13,7 @@ def notify_of_AN_to_be_checked(adoption_notice):
|
|||||||
for user in users_to_notify:
|
for user in users_to_notify:
|
||||||
Notification.objects.create(adoption_notice=adoption_notice,
|
Notification.objects.create(adoption_notice=adoption_notice,
|
||||||
user_to_notify=user,
|
user_to_notify=user,
|
||||||
notification_type=NotificationTypeChoices.AN_IS_TO_BE_CHECKED,
|
notification_type=ntc.AN_IS_TO_BE_CHECKED,
|
||||||
title=f" Prüfe Vermittlung {adoption_notice}",
|
title=f" Prüfe Vermittlung {adoption_notice}",
|
||||||
text=f"{adoption_notice} muss geprüft werden bevor sie veröffentlicht wird.",
|
text=f"{adoption_notice} muss geprüft werden bevor sie veröffentlicht wird.",
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user