Skip to content
Snippets Groups Projects
Select Git revision
  • 89cf486dbf72092773f7029900b5079a4d575c0d
  • main default protected
  • feature/export-filtering
  • feature/clear-schedule-button
  • fix/responsive-cols-in-polls
  • feature/preference-polling-form
  • feature/json-export-via-rest-framework
  • feature/json-schedule-import-tests
  • fix/add-room-import-only-once
  • ak-import
  • renovate/django-simple-history-3.x
  • renovate/django-debug-toolbar-4.x
  • renovate/django-5.x
  • renovate/mysqlclient-2.x
14 results

models.py

Blame
  • Forked from KIF / AKPlanning
    Source project has a limited visibility.
    • Benjamin Hättasch's avatar
      a39a5311
      Introduce detail and edit URLs as properties in AK model · a39a5311
      Benjamin Hättasch authored and Nadja Geisler's avatar Nadja Geisler committed
      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
      a39a5311
      History
      Introduce detail and edit URLs as properties in AK model
      Benjamin Hättasch authored and Nadja Geisler's avatar Nadja Geisler committed
      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)