Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / project_notif.py @ 19eb3ee6

History | View | Annotate | Download (3 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
SENDER = settings.SERVER_EMAIL
14
ADMINS = settings.ADMINS
15

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

    
28
def application_submit_notify(application):
29
    try:
30
        notification = build_notification(
31
            SENDER,
32
            [i[1] for i in ADMINS],
33
            _(settings.PROJECT_CREATION_SUBJECT) % application.__dict__,
34
            template='im/projects/project_creation_notification.txt',
35
            dictionary={'object':application})
36
        notification.send()
37
    except NotificationError, e:
38
        logger.error(e.message)
39

    
40
def application_deny_notify(application):
41
    try:
42
        notification = build_notification(
43
            SENDER,
44
            [application.owner.email],
45
            _(settings.PROJECT_DENIED_SUBJECT) % application.__dict__,
46
            template='im/projects/project_denial_notification.txt',
47
            dictionary={'object':application})
48
        notification.send()
49
    except NotificationError, e:
50
        logger.error(e.message)
51

    
52
def application_approve_notify(application):
53
    try:
54
        notification = build_notification(
55
            SENDER,
56
            [application.owner.email],
57
            _(settings.PROJECT_APPROVED_SUBJECT) % application.__dict__,
58
            template='im/projects/project_approval_notification.txt',
59
            dictionary={'object':application})
60
        notification.send()
61
    except NotificationError, e:
62
        logger.error(e.message)
63

    
64
def project_termination_notify(project):
65
    try:
66
        notification = build_notification(
67
            SENDER,
68
            [project.application.owner.email],
69
            _(settings.PROJECT_TERMINATION_SUBJECT) % project.__dict__,
70
            template='im/projects/project_termination_notification.txt',
71
            dictionary={'object':project}
72
        ).send()
73
    except NotificationError, e:
74
        logger.error(e.message)
75

    
76
def project_suspension_notify(project):
77
    try:
78
        notification = build_notification(
79
            SENDER,
80
            [project.application.owner.email],
81
            _(settings.PROJECT_SUSPENSION_SUBJECT) % project.__dict__,
82
            template='im/projects/project_suspension_notification.txt',
83
            dictionary={'object':project}
84
        ).send()
85
    except NotificationError, e:
86
        logger.error(e.message)