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
|
|
|
|
|
|
|
|
|
|
|
|
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-04-12 21:37:03 +00:00
|
|
|
greeting = _("Moin,") + "\r\n"
|
2024-06-08 07:31:23 +00:00
|
|
|
new_report_text = _("es wurde ein Regelverstoß gemeldet.") + "\r\n"
|
2024-03-25 09:49:56 +00:00
|
|
|
if len(report.reported_broken_rules.all()) > 0:
|
2024-05-30 13:28:23 +00:00
|
|
|
reported_rules_text = (f"Ein Verstoß gegen die folgenden Regeln wurde gemeldet:\r\n"
|
|
|
|
f"- {'\r\n - '.join([str(r) for r in report.reported_broken_rules.all()])}\r\n")
|
2024-03-25 09:49:56 +00:00
|
|
|
else:
|
|
|
|
reported_rules_text = f"Es wurden keine Regeln angegeben gegen die Verstoßen wurde.\r\n"
|
2024-05-30 13:28:23 +00:00
|
|
|
if report.user_comment:
|
|
|
|
comment_text = f'Kommentar zum Report: "{report.user_comment}"\r\n'
|
2024-03-25 09:49:56 +00:00
|
|
|
else:
|
|
|
|
comment_text = f"Es wurde kein Kommentar hinzugefügt.\r\n"
|
|
|
|
|
|
|
|
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()
|