Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / project_notif.py @ 5083fc47

History | View | Annotate | Download (5.4 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
    app = project.application
117
    try:
118
        build_notification(
119
            SENDER,
120
            [project.application.owner.email],
121
            _(messages.PROJECT_TERMINATION_SUBJECT) % app.__dict__,
122
            template='im/projects/project_termination_notification.txt',
123
            dictionary={'object': project}
124
        ).send()
125
    except NotificationError, e:
126
        logger.error(e.message)
127

    
128

    
129
def project_suspension_notify(project):
130
    try:
131
        build_notification(
132
            SENDER,
133
            [project.application.owner.email],
134
            _(messages.PROJECT_SUSPENSION_SUBJECT) % project.__dict__,
135
            template='im/projects/project_suspension_notification.txt',
136
            dictionary={'object': project}
137
        ).send()
138
    except NotificationError, e:
139
        logger.error(e.message)
140

    
141

    
142
def project_unsuspension_notify(project):
143
    try:
144
        build_notification(
145
            SENDER,
146
            [project.application.owner.email],
147
            _(messages.PROJECT_UNSUSPENSION_SUBJECT) % project.__dict__,
148
            template='im/projects/project_unsuspension_notification.txt',
149
            dictionary={'object': project}
150
        ).send()
151
    except NotificationError, e:
152
        logger.error(e.message)
153

    
154

    
155
def project_reinstatement_notify(project):
156
    try:
157
        build_notification(
158
            SENDER,
159
            [project.application.owner.email],
160
            _(messages.PROJECT_REINSTATEMENT_SUBJECT) % project.__dict__,
161
            template='im/projects/project_reinstatement_notification.txt',
162
            dictionary={'object': project}
163
        ).send()
164
    except NotificationError, e:
165
        logger.error(e.message)