Forked from
KIF / AKPlanning
-
This way, the frontend views will be used when AKSubmission is installed and active, or otherwise the link to the built-in AK edit form in backend This reduces the coupling between AKSubmission and other apps that previously needed that app Use that new property in all places where previously an URL to the submission view was used (for consistency and to allow changes in one place in AKSubmission, too) This implements #166
This way, the frontend views will be used when AKSubmission is installed and active, or otherwise the link to the built-in AK edit form in backend This reduces the coupling between AKSubmission and other apps that previously needed that app Use that new property in all places where previously an URL to the submission view was used (for consistency and to allow changes in one place in AKSubmission, too) This implements #166
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
models.py 1.80 KiB
from django.apps import apps
from django.conf import settings
from django.core.mail import EmailMessage
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.urls import reverse_lazy
from AKModel.models import AKOrgaMessage, AKSlot
@receiver(post_save, sender=AKOrgaMessage)
def orga_message_saved_handler(sender, instance: AKOrgaMessage, created, **kwargs):
# React to newly created Orga message by sending an email
if created and settings.SEND_MAILS:
host = 'https://' + settings.ALLOWED_HOSTS[0] if len(settings.ALLOWED_HOSTS) > 0 else 'http://127.0.0.1:8000'
url = f"{host}{instance.ak.detail_url}"
mail = EmailMessage(
f"[AKPlanning] New message for AK '{instance.ak}' ({instance.ak.event})",
f"{instance.text}\n\n{url}",
settings.DEFAULT_FROM_EMAIL,
[instance.ak.event.contact_email]
)
mail.send(fail_silently=True)
@receiver(post_save, sender=AKSlot)
def slot_created_handler(sender, instance: AKSlot, created, **kwargs):
# React to slots that are created after the plan was already published by sending an email
if created and settings.SEND_MAILS and apps.is_installed("AKPlan") and not instance.event.plan_hidden and instance.room is None and instance.start is None:
host = 'https://' + settings.ALLOWED_HOSTS[0] if len(settings.ALLOWED_HOSTS) > 0 else 'http://127.0.0.1:8000'
url = f"{host}{instance.ak.detail_url}"
mail = EmailMessage(
f"[AKPlanning] New slot for AK '{instance.ak}' ({instance.ak.event}) added",
f"New slot requested.\n\nAK: {instance.ak}\nDuration: {instance.duration}\n\n{url}",
settings.DEFAULT_FROM_EMAIL,
[instance.ak.event.contact_email]
)
mail.send(fail_silently=True)