2024-03-25 09:49:56 +00:00
|
|
|
import django.conf.global_settings
|
|
|
|
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from django.utils.translation import gettext
|
|
|
|
from django.conf import settings
|
|
|
|
from django.core import mail
|
2024-08-04 13:34:06 +00:00
|
|
|
from django.db.models import Q, Min
|
2024-06-08 07:31:23 +00:00
|
|
|
from fellchensammlung.models import User
|
2024-03-25 09:49:56 +00:00
|
|
|
from notfellchen.settings import host
|
|
|
|
|
2024-09-15 07:00:27 +00:00
|
|
|
NEWLINE = "\r\n"
|
2024-03-25 09:49:56 +00:00
|
|
|
|
|
|
|
def mail_admins_new_report(report):
|
2024-04-13 11:25:09 +00:00
|
|
|
subject = _("Neue Meldung")
|
2024-08-04 13:34:06 +00:00
|
|
|
for moderator in User.objects.filter(trust_level__gt=User.TRUST_LEVEL[User.MODERATOR]):
|
2024-09-15 07:00:27 +00:00
|
|
|
greeting = _("Moin,") + "{NEWLINE}"
|
|
|
|
new_report_text = _("es wurde ein Regelverstoß gemeldet.") + "{NEWLINE}"
|
2024-03-25 09:49:56 +00:00
|
|
|
if len(report.reported_broken_rules.all()) > 0:
|
2024-09-15 07:00:27 +00: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 09:49:56 +00:00
|
|
|
else:
|
2024-09-15 07:00:27 +00:00
|
|
|
reported_rules_text = f"Es wurden keine Regeln angegeben gegen die Verstoßen wurde.{NEWLINE}"
|
2024-05-30 13:28:23 +00:00
|
|
|
if report.user_comment:
|
2024-09-15 07:00:27 +00:00
|
|
|
comment_text = f'Kommentar zum Report: "{report.user_comment}"{NEWLINE}'
|
2024-03-25 09:49:56 +00:00
|
|
|
else:
|
2024-09-15 07:00:27 +00:00
|
|
|
comment_text = f"Es wurde kein Kommentar hinzugefügt.{NEWLINE}"
|
2024-03-25 09:49:56 +00: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 13:34:06 +00:00
|
|
|
message = mail.EmailMessage(subject, body_text, settings.DEFAULT_FROM_EMAIL, [moderator.email])
|
|
|
|
print("Sending email to ", moderator.email)
|
2024-03-25 09:49:56 +00:00
|
|
|
message.send()
|