Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / project_notif.py @ 469d0997

History | View | Annotate | Download (4.5 kB)

1
import logging
2
from django.utils.translation import ugettext as _
3
import astakos.im.settings as 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
ADMINS = settings.ADMINS
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.realname})
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.realname})
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,
73
            [i[1] for i in ADMINS],
74
            _(settings.PROJECT_CREATION_SUBJECT) % application.__dict__,
75
            template='im/projects/project_creation_notification.txt',
76
            dictionary={'object':application})
77
        notification.send()
78
    except NotificationError, e:
79
        logger.error(e.message)
80

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

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

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

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