Skip to content
Snippets Groups Projects
Commit 4a78bf7d authored by Benjamin Hättasch's avatar Benjamin Hättasch Committed by Nadja Geisler
Browse files

Introduce sending of mails a new slot is added for a published plan

This will send an email with information about the slot and a link to the corresponding AK to the contact mail adress specified for a given event, but only if the plan feature is used, the plan is already visible and the slot was not directly scheduled
This implements #117
parent c6e0e157
No related branches found
No related tags found
No related merge requests found
from django.apps import apps
from django.conf import settings from django.conf import settings
from django.core.mail import EmailMessage from django.core.mail import EmailMessage
from django.db.models.signals import post_save from django.db.models.signals import post_save
from django.dispatch import receiver from django.dispatch import receiver
from django.urls import reverse_lazy from django.urls import reverse_lazy
from AKModel.models import AKOrgaMessage from AKModel.models import AKOrgaMessage, AKSlot
@receiver(post_save, sender=AKOrgaMessage) @receiver(post_save, sender=AKOrgaMessage)
def orga_message_saved_handler(sender, instance: AKOrgaMessage, **kwargs): def orga_message_saved_handler(sender, instance: AKOrgaMessage, created, **kwargs):
# React to saved (thus new) Orga message by sending an email # React to newly created Orga message by sending an email
if settings.SEND_MAILS: 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' host = 'https://' + settings.ALLOWED_HOSTS[0] if len(settings.ALLOWED_HOSTS) > 0 else 'http://127.0.0.1:8000'
url = f"{host}{reverse_lazy('submit:ak_detail', kwargs={'pk': instance.ak.pk, 'event_slug': instance.ak.event.slug})}" url = f"{host}{reverse_lazy('submit:ak_detail', kwargs={'pk': instance.ak.pk, 'event_slug': instance.ak.event.slug})}"
...@@ -22,3 +23,20 @@ def orga_message_saved_handler(sender, instance: AKOrgaMessage, **kwargs): ...@@ -22,3 +23,20 @@ def orga_message_saved_handler(sender, instance: AKOrgaMessage, **kwargs):
[instance.ak.event.contact_email] [instance.ak.event.contact_email]
) )
mail.send(fail_silently=True) 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}{reverse_lazy('submit:ak_detail', kwargs={'pk': instance.ak.pk, 'event_slug': instance.ak.event.slug})}"
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment