2024-11-12 13:12:45 +01:00
|
|
|
from django.db.models.signals import post_save
|
|
|
|
from django.dispatch import receiver
|
2024-03-25 10:49:56 +01:00
|
|
|
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from django.conf import settings
|
|
|
|
from django.core import mail
|
2024-11-20 23:01:19 +01:00
|
|
|
from fellchensammlung.models import User, CommentNotification, BaseNotification, TrustLevel
|
2024-03-25 10:49:56 +01:00
|
|
|
from notfellchen.settings import host
|
|
|
|
|
2024-09-15 09:00:27 +02:00
|
|
|
NEWLINE = "\r\n"
|
2024-03-25 10:49:56 +01:00
|
|
|
|
2024-11-12 13:12:45 +01:00
|
|
|
|
2024-03-25 10:49:56 +01:00
|
|
|
def mail_admins_new_report(report):
|
2024-04-13 13:25:09 +02:00
|
|
|
subject = _("Neue Meldung")
|
2024-11-20 23:01:19 +01:00
|
|
|
for moderator in User.objects.filter(trust_level__gt=TrustLevel.MODERATOR):
|
2024-09-15 09:00:27 +02:00
|
|
|
greeting = _("Moin,") + "{NEWLINE}"
|
|
|
|
new_report_text = _("es wurde ein Regelverstoß gemeldet.") + "{NEWLINE}"
|
2024-03-25 10:49:56 +01:00
|
|
|
if len(report.reported_broken_rules.all()) > 0:
|
2024-09-15 09:00:27 +02:00
|
|
|
reported_rules_text = (f"Ein Verstoß gegen die folgenden Regeln wurde gemeldet:{NEWLINE}"
|
|
|
|
f"- {f'{NEWLINE} - '.join([str(r) for r in report.reported_broken_rules.all()])}{NEWLINE}")
|
2024-03-25 10:49:56 +01:00
|
|
|
else:
|
2024-09-15 09:00:27 +02:00
|
|
|
reported_rules_text = f"Es wurden keine Regeln angegeben gegen die Verstoßen wurde.{NEWLINE}"
|
2024-05-30 15:28:23 +02:00
|
|
|
if report.user_comment:
|
2024-09-15 09:00:27 +02:00
|
|
|
comment_text = f'Kommentar zum Report: "{report.user_comment}"{NEWLINE}'
|
2024-03-25 10:49:56 +01:00
|
|
|
else:
|
2024-09-15 09:00:27 +02:00
|
|
|
comment_text = f"Es wurde kein Kommentar hinzugefügt.{NEWLINE}"
|
2024-03-25 10:49:56 +01:00
|
|
|
|
|
|
|
report_url = "https://" + host + report.get_absolute_url()
|
|
|
|
link_text = f"Um alle Details zu sehen, geh bitte auf: {report_url}"
|
|
|
|
body_text = greeting + new_report_text + reported_rules_text + comment_text + link_text
|
2024-08-04 15:34:06 +02:00
|
|
|
message = mail.EmailMessage(subject, body_text, settings.DEFAULT_FROM_EMAIL, [moderator.email])
|
2024-03-25 10:49:56 +01:00
|
|
|
message.send()
|
2024-11-12 13:12:45 +01:00
|
|
|
|
|
|
|
|
2024-11-20 20:26:44 +01:00
|
|
|
def send_notification_email(notification_pk):
|
|
|
|
try:
|
|
|
|
notification = CommentNotification.objects.get(pk=notification_pk)
|
|
|
|
except CommentNotification.DoesNotExist:
|
|
|
|
notification = BaseNotification.objects.get(pk=notification_pk)
|
|
|
|
subject = f"🔔 {notification.title}"
|
|
|
|
body_text = notification.text
|
|
|
|
message = mail.EmailMessage(subject, body_text, settings.DEFAULT_FROM_EMAIL, [notification.user.email])
|
|
|
|
message.send()
|