root / snf-astakos-app / astakos / im / project_notif.py @ 8fb8d0cf
History | View | Annotate | Download (4.6 kB)
1 |
import logging |
---|---|
2 |
from django.utils.translation import ugettext as _ |
3 |
from astakos.im import settings |
4 |
from astakos.im.notifications import build_notification, NotificationError |
5 |
from astakos.im import messages |
6 |
|
7 |
logger = logging.getLogger(__name__) |
8 |
|
9 |
MEM_CHANGE_NOTIF = { |
10 |
'subject': _(messages.PROJECT_MEMBERSHIP_CHANGE_SUBJECT),
|
11 |
'template': 'im/projects/project_membership_change_notification.txt', |
12 |
} |
13 |
|
14 |
MEM_ENROLL_NOTIF = { |
15 |
'subject': _(messages.PROJECT_MEMBERSHIP_ENROLL_SUBJECT),
|
16 |
'template': 'im/projects/project_membership_enroll_notification.txt', |
17 |
} |
18 |
|
19 |
SENDER = settings.SERVER_EMAIL |
20 |
NOTIFY_RECIPIENTS = [e[1] for e in settings.MANAGERS + settings.HELPDESK] |
21 |
|
22 |
|
23 |
def membership_change_notify(project, user, action): |
24 |
try:
|
25 |
notification = build_notification( |
26 |
SENDER, |
27 |
[user.email], |
28 |
MEM_CHANGE_NOTIF['subject'] % project.__dict__,
|
29 |
template=MEM_CHANGE_NOTIF['template'],
|
30 |
dictionary={'object': project, 'action': action}) |
31 |
notification.send() |
32 |
except NotificationError, e:
|
33 |
logger.error(e.message) |
34 |
|
35 |
|
36 |
def membership_enroll_notify(project, user): |
37 |
try:
|
38 |
notification = build_notification( |
39 |
SENDER, |
40 |
[user.email], |
41 |
MEM_ENROLL_NOTIF['subject'] % project.__dict__,
|
42 |
template=MEM_ENROLL_NOTIF['template'],
|
43 |
dictionary={'object': project})
|
44 |
notification.send() |
45 |
except NotificationError, e:
|
46 |
logger.error(e.message) |
47 |
|
48 |
|
49 |
def membership_request_notify(project, requested_user): |
50 |
try:
|
51 |
notification = build_notification( |
52 |
SENDER, |
53 |
[project.application.owner.email], |
54 |
_(messages.PROJECT_MEMBERSHIP_REQUEST_SUBJECT) % project.__dict__, |
55 |
template='im/projects/project_membership_request_notification.txt',
|
56 |
dictionary={'object': project, 'user': requested_user.email}) |
57 |
notification.send() |
58 |
except NotificationError, e:
|
59 |
logger.error(e.message) |
60 |
|
61 |
|
62 |
def membership_leave_request_notify(project, requested_user): |
63 |
template = 'im/projects/project_membership_leave_request_notification.txt'
|
64 |
try:
|
65 |
notification = build_notification( |
66 |
SENDER, |
67 |
[project.application.owner.email], |
68 |
_(messages.PROJECT_MEMBERSHIP_LEAVE_REQUEST_SUBJECT) % |
69 |
project.__dict__, |
70 |
template=template, |
71 |
dictionary={'object': project, 'user': requested_user.email}) |
72 |
notification.send() |
73 |
except NotificationError, e:
|
74 |
logger.error(e.message) |
75 |
|
76 |
|
77 |
def application_submit_notify(application): |
78 |
try:
|
79 |
notification = build_notification( |
80 |
SENDER, NOTIFY_RECIPIENTS, |
81 |
_(messages.PROJECT_CREATION_SUBJECT) % application.__dict__, |
82 |
template='im/projects/project_creation_notification.txt',
|
83 |
dictionary={'object': application})
|
84 |
notification.send() |
85 |
except NotificationError, e:
|
86 |
logger.error(e.message) |
87 |
|
88 |
|
89 |
def application_deny_notify(application): |
90 |
try:
|
91 |
notification = build_notification( |
92 |
SENDER, |
93 |
[application.owner.email], |
94 |
_(messages.PROJECT_DENIED_SUBJECT) % application.__dict__, |
95 |
template='im/projects/project_denial_notification.txt',
|
96 |
dictionary={'object': application})
|
97 |
notification.send() |
98 |
except NotificationError, e:
|
99 |
logger.error(e.message) |
100 |
|
101 |
|
102 |
def application_approve_notify(application): |
103 |
try:
|
104 |
notification = build_notification( |
105 |
SENDER, |
106 |
[application.owner.email], |
107 |
_(messages.PROJECT_APPROVED_SUBJECT) % application.__dict__, |
108 |
template='im/projects/project_approval_notification.txt',
|
109 |
dictionary={'object': application})
|
110 |
notification.send() |
111 |
except NotificationError, e:
|
112 |
logger.error(e.message) |
113 |
|
114 |
|
115 |
def project_termination_notify(project): |
116 |
try:
|
117 |
notification = build_notification( |
118 |
SENDER, |
119 |
[project.application.owner.email], |
120 |
_(messages.PROJECT_TERMINATION_SUBJECT) % project.__dict__, |
121 |
template='im/projects/project_termination_notification.txt',
|
122 |
dictionary={'object': project}
|
123 |
).send() |
124 |
except NotificationError, e:
|
125 |
logger.error(e.message) |
126 |
|
127 |
|
128 |
def project_suspension_notify(project): |
129 |
try:
|
130 |
notification = build_notification( |
131 |
SENDER, |
132 |
[project.application.owner.email], |
133 |
_(messages.PROJECT_SUSPENSION_SUBJECT) % project.__dict__, |
134 |
template='im/projects/project_suspension_notification.txt',
|
135 |
dictionary={'object': project}
|
136 |
).send() |
137 |
except NotificationError, e:
|
138 |
logger.error(e.message) |