-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
341 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright The IETF Trust 2024, All Rights Reserved | ||
|
||
from django.apps import AppConfig | ||
|
||
|
||
class CommunityConfig(AppConfig): | ||
name = "ietf.community" | ||
|
||
def ready(self): | ||
"""Initialize the app after the registry is populated""" | ||
# implicitly connects @receiver-decorated signals | ||
from . import signals # pyflakes: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.