Skip to content
Snippets Groups Projects
Select Git revision
  • 9b32e74f9af9468a30aeeb5ae9dce805cc715e03
  • renovate/django-split-settings-1.x
  • renovate/djangorestframework-3.x
  • main
  • 520-improve-trackmanager
  • 520-fix-scheduling
  • 520-akowner
  • 520-status
  • 520-message-resolved
  • 520-improve-scheduling-2
  • renovate/django-bootstrap5-24.x
  • 520-improve-submission
  • 520-improve-scheduling
  • 520-improve-wall
  • 520-fix-event-wizard-datepicker
  • 520-upgrades
  • renovate/tzdata-2023.x
  • renovate/django-5.x
  • renovate/fontawesomefree-6.x
  • renovate/sphinx-rtd-theme-2.x
  • renovate/sphinxcontrib-apidoc-0.x
21 results

apps.py

Blame
  • Forked from KIF / AKPlanning
    Source project has a limited visibility.
    • Benjamin Hättasch's avatar
      aca81a1f
      Introduce custom admin · aca81a1f
      Benjamin Hättasch authored
      This is the base for custom admin views (with admin design and permission checking)
      Replace default admin site with custom admin site in AKModel
      Use custom admin index template & apply first basic change
      Introduce custom admin base template (including bootstrap loading)
      Introduce Mixin for AdminViews
      aca81a1f
      History
      Introduce custom admin
      Benjamin Hättasch authored
      This is the base for custom admin views (with admin design and permission checking)
      Replace default admin site with custom admin site in AKModel
      Use custom admin index template & apply first basic change
      Introduce custom admin base template (including bootstrap loading)
      Introduce Mixin for AdminViews
    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)