1
+ # Third Party (PyPI) Imports
2
+ import rollbar
3
+
1
4
# Django Imports
2
5
from django .apps import AppConfig
6
+ from django .conf import settings
3
7
from django .db .models import signals
4
8
5
9
# HTK Imports
6
10
from htk .app_config import HtkAppConfig
11
+ from htk .decorators .classes import disable_for_loaddata
12
+ from htk .utils import (
13
+ htk_setting ,
14
+ resolve_model_dynamically ,
15
+ )
16
+
17
+
18
+ # isort: off
19
+
20
+
21
+ @disable_for_loaddata
22
+ def organization_invitation_created (sender , instance , created , ** kwargs ):
23
+ """Signal handler for when a new OrganizationInvitation object is created"""
24
+ if created :
25
+ invitation = instance
26
+
27
+ if not settings .TEST and htk_setting ('HTK_SLACK_NOTIFICATIONS_ENABLED' ):
28
+ try :
29
+ from htk .utils .notifications import slack_notify
30
+
31
+ msg = invitation .build_notification_message__created ()
32
+ slack_notify (msg )
33
+ except :
34
+ rollbar .report_exc_info ()
7
35
8
36
9
37
class HtkOrganizationAppConfig (HtkAppConfig ):
@@ -12,4 +40,12 @@ class HtkOrganizationAppConfig(HtkAppConfig):
12
40
verbose_name = 'Organizations'
13
41
14
42
def ready (self ):
15
- pass
43
+ OrganizationInvitation = resolve_model_dynamically (
44
+ htk_setting ('HTK_ORGANIZATION_INVITATION_MODEL' )
45
+ )
46
+
47
+ signals .post_save .connect (
48
+ organization_invitation_created ,
49
+ sender = OrganizationInvitation ,
50
+ dispatch_uid = 'htk_organization_invitation_created' ,
51
+ )
0 commit comments