root / snf-astakos-app / astakos / im / project_notif.py @ b1cb2583
History | View | Annotate | Download (6.9 kB)
1 |
# Copyright 2013 GRNET S.A. All rights reserved.
|
---|---|
2 |
#
|
3 |
# Redistribution and use in source and binary forms, with or
|
4 |
# without modification, are permitted provided that the following
|
5 |
# conditions are met:
|
6 |
#
|
7 |
# 1. Redistributions of source code must retain the above
|
8 |
# copyright notice, this list of conditions and the following
|
9 |
# disclaimer.
|
10 |
#
|
11 |
# 2. Redistributions in binary form must reproduce the above
|
12 |
# copyright notice, this list of conditions and the following
|
13 |
# disclaimer in the documentation and/or other materials
|
14 |
# provided with the distribution.
|
15 |
#
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
# POSSIBILITY OF SUCH DAMAGE.
|
28 |
#
|
29 |
# The views and conclusions contained in the software and
|
30 |
# documentation are those of the authors and should not be
|
31 |
# interpreted as representing official policies, either expressed
|
32 |
# or implied, of GRNET S.A.
|
33 |
|
34 |
import logging |
35 |
from django.utils.translation import ugettext as _ |
36 |
from astakos.im import settings |
37 |
from astakos.im.notifications import build_notification, NotificationError |
38 |
from astakos.im import messages |
39 |
|
40 |
logger = logging.getLogger(__name__) |
41 |
|
42 |
MEM_CHANGE_NOTIF = { |
43 |
'subject': _(messages.PROJECT_MEMBERSHIP_CHANGE_SUBJECT),
|
44 |
'template': 'im/projects/project_membership_change_notification.txt', |
45 |
} |
46 |
|
47 |
MEM_ENROLL_NOTIF = { |
48 |
'subject': _(messages.PROJECT_MEMBERSHIP_ENROLL_SUBJECT),
|
49 |
'template': 'im/projects/project_membership_enroll_notification.txt', |
50 |
} |
51 |
|
52 |
SENDER = settings.SERVER_EMAIL |
53 |
NOTIFY_RECIPIENTS = [e[1] for e in settings.MANAGERS + settings.HELPDESK] |
54 |
|
55 |
|
56 |
def membership_change_notify(project, user, action): |
57 |
try:
|
58 |
notification = build_notification( |
59 |
SENDER, |
60 |
[user.email], |
61 |
MEM_CHANGE_NOTIF['subject'] % project.__dict__,
|
62 |
template=MEM_CHANGE_NOTIF['template'],
|
63 |
dictionary={'object': project, 'action': action}) |
64 |
notification.send() |
65 |
except NotificationError, e:
|
66 |
logger.error(e.message) |
67 |
|
68 |
|
69 |
def membership_enroll_notify(project, user): |
70 |
try:
|
71 |
notification = build_notification( |
72 |
SENDER, |
73 |
[user.email], |
74 |
MEM_ENROLL_NOTIF['subject'] % project.__dict__,
|
75 |
template=MEM_ENROLL_NOTIF['template'],
|
76 |
dictionary={'object': project})
|
77 |
notification.send() |
78 |
except NotificationError, e:
|
79 |
logger.error(e.message) |
80 |
|
81 |
|
82 |
def membership_request_notify(project, requested_user): |
83 |
try:
|
84 |
notification = build_notification( |
85 |
SENDER, |
86 |
[project.application.owner.email], |
87 |
_(messages.PROJECT_MEMBERSHIP_REQUEST_SUBJECT) % project.__dict__, |
88 |
template='im/projects/project_membership_request_notification.txt',
|
89 |
dictionary={'object': project, 'user': requested_user.email}) |
90 |
notification.send() |
91 |
except NotificationError, e:
|
92 |
logger.error(e.message) |
93 |
|
94 |
|
95 |
def membership_leave_request_notify(project, requested_user): |
96 |
template = 'im/projects/project_membership_leave_request_notification.txt'
|
97 |
try:
|
98 |
notification = build_notification( |
99 |
SENDER, |
100 |
[project.application.owner.email], |
101 |
_(messages.PROJECT_MEMBERSHIP_LEAVE_REQUEST_SUBJECT) % |
102 |
project.__dict__, |
103 |
template=template, |
104 |
dictionary={'object': project, 'user': requested_user.email}) |
105 |
notification.send() |
106 |
except NotificationError, e:
|
107 |
logger.error(e.message) |
108 |
|
109 |
|
110 |
def application_submit_notify(application): |
111 |
try:
|
112 |
notification = build_notification( |
113 |
SENDER, NOTIFY_RECIPIENTS, |
114 |
_(messages.PROJECT_CREATION_SUBJECT) % application.__dict__, |
115 |
template='im/projects/project_creation_notification.txt',
|
116 |
dictionary={'object': application})
|
117 |
notification.send() |
118 |
except NotificationError, e:
|
119 |
logger.error(e.message) |
120 |
|
121 |
|
122 |
def application_deny_notify(application): |
123 |
try:
|
124 |
notification = build_notification( |
125 |
SENDER, |
126 |
[application.owner.email], |
127 |
_(messages.PROJECT_DENIED_SUBJECT) % application.__dict__, |
128 |
template='im/projects/project_denial_notification.txt',
|
129 |
dictionary={'object': application})
|
130 |
notification.send() |
131 |
except NotificationError, e:
|
132 |
logger.error(e.message) |
133 |
|
134 |
|
135 |
def application_approve_notify(application): |
136 |
try:
|
137 |
notification = build_notification( |
138 |
SENDER, |
139 |
[application.owner.email], |
140 |
_(messages.PROJECT_APPROVED_SUBJECT) % application.__dict__, |
141 |
template='im/projects/project_approval_notification.txt',
|
142 |
dictionary={'object': application})
|
143 |
notification.send() |
144 |
except NotificationError, e:
|
145 |
logger.error(e.message) |
146 |
|
147 |
|
148 |
def project_termination_notify(project): |
149 |
app = project.application |
150 |
try:
|
151 |
build_notification( |
152 |
SENDER, |
153 |
[project.application.owner.email], |
154 |
_(messages.PROJECT_TERMINATION_SUBJECT) % app.__dict__, |
155 |
template='im/projects/project_termination_notification.txt',
|
156 |
dictionary={'object': project}
|
157 |
).send() |
158 |
except NotificationError, e:
|
159 |
logger.error(e.message) |
160 |
|
161 |
|
162 |
def project_suspension_notify(project): |
163 |
try:
|
164 |
build_notification( |
165 |
SENDER, |
166 |
[project.application.owner.email], |
167 |
_(messages.PROJECT_SUSPENSION_SUBJECT) % project.__dict__, |
168 |
template='im/projects/project_suspension_notification.txt',
|
169 |
dictionary={'object': project}
|
170 |
).send() |
171 |
except NotificationError, e:
|
172 |
logger.error(e.message) |
173 |
|
174 |
|
175 |
def project_unsuspension_notify(project): |
176 |
try:
|
177 |
build_notification( |
178 |
SENDER, |
179 |
[project.application.owner.email], |
180 |
_(messages.PROJECT_UNSUSPENSION_SUBJECT) % project.__dict__, |
181 |
template='im/projects/project_unsuspension_notification.txt',
|
182 |
dictionary={'object': project}
|
183 |
).send() |
184 |
except NotificationError, e:
|
185 |
logger.error(e.message) |
186 |
|
187 |
|
188 |
def project_reinstatement_notify(project): |
189 |
try:
|
190 |
build_notification( |
191 |
SENDER, |
192 |
[project.application.owner.email], |
193 |
_(messages.PROJECT_REINSTATEMENT_SUBJECT) % project.__dict__, |
194 |
template='im/projects/project_reinstatement_notification.txt',
|
195 |
dictionary={'object': project}
|
196 |
).send() |
197 |
except NotificationError, e:
|
198 |
logger.error(e.message) |