forked from ietf-tools/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignals.py
More file actions
44 lines (33 loc) · 1.56 KB
/
Copy pathsignals.py
File metadata and controls
44 lines (33 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Copyright The IETF Trust 2024, All Rights Reserved
from django.conf import settings
from django.db import transaction
from django.db.models.signals import post_save
from django.dispatch import receiver
from ietf.doc.models import DocEvent
from .tasks import notify_event_to_subscribers_task
def notify_of_event(event: DocEvent):
"""Send subscriber notification emails for a 'draft'-related DocEvent
If the event is attached to a draft of type 'doc', queues a task to send notification emails to
community list subscribers. No emails will be sent when SERVER_MODE is 'test'.
"""
if event.doc.type_id != "draft":
return
if getattr(event, "skip_community_list_notification", False):
return
# kludge alert: queuing a celery task in response to a signal can cause unexpected attempts to
# start a Celery task during tests. To prevent this, don't queue a celery task if we're running
# tests.
if settings.SERVER_MODE != "test":
# Wrap in on_commit in case a transaction is open
transaction.on_commit(
lambda: notify_event_to_subscribers_task.delay(event_id=event.pk)
)
# dispatch_uid ensures only a single signal receiver binding is made
@receiver(post_save, dispatch_uid="notify_of_events_receiver_uid")
def notify_of_events_receiver(sender, instance, **kwargs):
"""Call notify_of_event after saving a new DocEvent"""
if not isinstance(instance, DocEvent):
return
if not kwargs.get("created", False):
return # only notify on creation
notify_of_event(instance)