port to new django, AI automated

This commit is contained in:
2026-03-30 22:35:36 +02:00
parent e2d166e437
commit 372da3caa9
215 changed files with 9283 additions and 2981 deletions

View File

@@ -1,12 +1,12 @@
from django.db import models
from django.utils.translation import ugettext as _
from django.contrib.auth.models import User
from django.core.mail import EmailMultiAlternatives
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _
from musicians.models import Musician
from django.template.loader import get_template
from django.template import Context
class Message(models.Model):
@@ -14,30 +14,41 @@ class Message(models.Model):
text = models.TextField(blank=False, verbose_name=_("text"))
creation_time = models.DateTimeField(verbose_name=_("creation_time"))
author = models.ForeignKey(User, verbose_name=_("Author"), on_delete=models.PROTECT)
def __unicode__(self):
author = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_("Author"))
class Meta:
ordering = ["-creation_time"]
def __str__(self):
return self.author.username + " : " + self.titel
@receiver(post_save, sender=Message)
def my_handler(sender, instance, created, **kwargs):
def send_forum_notification(sender, instance, created, **kwargs):
"""Send email notification when a new message is created."""
if not created:
return
receivers = [m.user.email for m in Musician.objects.all()]
receivers = [m.user.email for m in Musician.objects.all() if m.user.email]
if not receivers:
return
subject = "Blechreiz Forum: " + instance.titel
from_email = 'forum@blechreiz.com'
from_email = "forum@blechreiz.com"
c = {'messages': Message.objects.all().order_by('-creation_time')[:10]}
context = {"messages": Message.objects.all().order_by("-creation_time")[:10]}
text_template = get_template("simpleforum/mail.txt")
# html_template = get_template( "simpleforum/mail.html" )
text_content = text_template.render(Context(c))
# html_content = html_template.render( Context(c) )
text_content = render_to_string("simpleforum/mail.txt", context)
msg = EmailMultiAlternatives(subject, text_content, from_email, receivers)
# msg.attach_alternative( html_content, "text/html" )
msg.send()
# Uncomment to add HTML version:
# html_content = render_to_string("simpleforum/mail.html", context)
# msg.attach_alternative(html_content, "text/html")
try:
msg.send()
except Exception:
# Log the error but don't crash
pass