Skip to content
Snippets Groups Projects
Select Git revision
  • master
  • pipefail
  • fixes/ansible-lint
  • v4.0.0
  • v3.0.1
  • v3.0.0
  • v2.6.1
  • v2.6.0
  • v2.5.0
  • v2.4.0
  • v2.3.0
  • v2.2.1
  • v2.2.0
  • v2.1.1
  • v2.1.0
  • v2.0.5
  • v2.0.4
  • v2.0.3
  • v2.0.2
  • v2.0.1
  • v2.0
  • v2.0.0
  • v1.6
23 results

README.md

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    models.py 1.93 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 AKModel.models import AKOrgaMessage, AKSlot
    
    
    @receiver(post_save, sender=AKOrgaMessage)
    def orga_message_saved_handler(sender, instance: AKOrgaMessage, created, **kwargs): # pylint: disable=unused-argument
        """
        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): # pylint: disable=unused-argument
        """
        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: # pylint: disable=too-many-boolean-expressions,line-too-long
            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)