Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / project_notif.py @ 3805be31

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
def membership_change_notify(project, user, action):
23
    try:
24
        notification = build_notification(
25
            SENDER,
26
            [user.email],
27
            MEM_CHANGE_NOTIF['subject'] % project.__dict__,
28
            template= MEM_CHANGE_NOTIF['template'],
29
            dictionary={'object':project, 'action':action})
30
        notification.send()
31
    except NotificationError, e:
32
        logger.error(e.message)
33

    
34
def membership_enroll_notify(project, user):
35
    try:
36
        notification = build_notification(
37
            SENDER,
38
            [user.email],
39
            MEM_ENROLL_NOTIF['subject'] % project.__dict__,
40
            template= MEM_ENROLL_NOTIF['template'],
41
            dictionary={'object':project})
42
        notification.send()
43
    except NotificationError, e:
44
        logger.error(e.message)
45

    
46
def membership_request_notify(project, requested_user):
47
    try:
48
        notification = build_notification(
49
            SENDER,
50
            [project.application.owner.email],
51
            _(messages.PROJECT_MEMBERSHIP_REQUEST_SUBJECT) % project.__dict__,
52
            template= 'im/projects/project_membership_request_notification.txt',
53
            dictionary={'object':project, 'user':requested_user.email})
54
        notification.send()
55
    except NotificationError, e:
56
        logger.error(e.message)
57

    
58
def membership_leave_request_notify(project, requested_user):
59
    try:
60
        notification = build_notification(
61
            SENDER,
62
            [project.application.owner.email],
63
            _(messages.PROJECT_MEMBERSHIP_LEAVE_REQUEST_SUBJECT) %
64
            project.__dict__,
65
            template= 'im/projects/project_membership_leave_request_notification.txt',
66
            dictionary={'object':project, 'user':requested_user.email})
67
        notification.send()
68
    except NotificationError, e:
69
        logger.error(e.message)
70

    
71
def application_submit_notify(application):
72
    try:
73
        notification = build_notification(
74
            SENDER, NOTIFY_RECIPIENTS,
75
            _(messages.PROJECT_CREATION_SUBJECT) % application.__dict__,
76
            template='im/projects/project_creation_notification.txt',
77
            dictionary={'object':application})
78
        notification.send()
79
    except NotificationError, e:
80
        logger.error(e.message)
81

    
82
def application_deny_notify(application):
83
    try:
84
        notification = build_notification(
85
            SENDER,
86
            [application.owner.email],
87
            _(messages.PROJECT_DENIED_SUBJECT) % application.__dict__,
88
            template='im/projects/project_denial_notification.txt',
89
            dictionary={'object':application})
90
        notification.send()
91
    except NotificationError, e:
92
        logger.error(e.message)
93

    
94
def application_approve_notify(application):
95
    try:
96
        notification = build_notification(
97
            SENDER,
98
            [application.owner.email],
99
            _(messages.PROJECT_APPROVED_SUBJECT) % application.__dict__,
100
            template='im/projects/project_approval_notification.txt',
101
            dictionary={'object':application})
102
        notification.send()
103
    except NotificationError, e:
104
        logger.error(e.message)
105

    
106
def project_termination_notify(project):
107
    app = project.application
108
    try:
109
        notification = build_notification(
110
            SENDER,
111
            [project.application.owner.email],
112
            _(messages.PROJECT_TERMINATION_SUBJECT) % app.__dict__,
113
            template='im/projects/project_termination_notification.txt',
114
            dictionary={'object':project}
115
        ).send()
116
    except NotificationError, e:
117
        logger.error(e.message)
118

    
119
def project_suspension_notify(project):
120
    try:
121
        notification = build_notification(
122
            SENDER,
123
            [project.application.owner.email],
124
            _(messages.PROJECT_SUSPENSION_SUBJECT) % project.__dict__,
125
            template='im/projects/project_suspension_notification.txt',
126
            dictionary={'object':project}
127
        ).send()
128
    except NotificationError, e:
129
        logger.error(e.message)