Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / project_notif.py @ 8998f09a

History | View | Annotate | Download (4.5 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

    
6
logger = logging.getLogger(__name__)
7

    
8
MEM_CHANGE_NOTIF = {
9
    'subject' : _(settings.PROJECT_MEMBERSHIP_CHANGE_SUBJECT),
10
    'template': 'im/projects/project_membership_change_notification.txt',
11
    }
12

    
13
MEM_ENROLL_NOTIF = {
14
    'subject' : _(settings.PROJECT_MEMBERSHIP_ENROLL_SUBJECT),
15
    'template': 'im/projects/project_membership_enroll_notification.txt',
16
    }
17

    
18
SENDER = settings.SERVER_EMAIL
19
NOTIFY_RECIPIENTS = [e[1] for e in settings.MANAGERS + settings.HELPDESK]
20

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

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

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

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

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

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

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

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

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