Revision 84498bca

b/snf-astakos-app/astakos/im/functions.py
574 574
                                  reason=reason)
575 575
        logger.info("User %s requested to leave %s." %
576 576
                    (request_user.log_display, project))
577
        project_notif.membership_leave_request_notify(
578
            project, membership.person)
577
        project_notif.membership_request_notify(
578
            project, membership.person, "leave")
579 579
    return auto_accepted
580 580

  
581 581

  
......
635 635
        logger.info("User %s joined %s." %
636 636
                    (request_user.log_display, project))
637 637
    else:
638
        project_notif.membership_request_notify(project, membership.person)
638
        project_notif.membership_request_notify(
639
            project, membership.person, "join")
639 640
        logger.info("User %s requested to join %s." %
640 641
                    (request_user.log_display, project))
641 642
    return membership
......
724 725
        set_resource_policies(application, policies)
725 726
    logger.info("User %s submitted %s." %
726 727
                (request_user.log_display, application.log_display))
727
    project_notif.application_submit_notify(application)
728
    project_notif.application_notify(application, "submit")
728 729
    return application
729 730

  
730 731

  
......
811 812
    application.deny(actor=request_user, reason=reason)
812 813
    logger.info("%s has been denied with reason \"%s\"." %
813 814
                (application.log_display, reason))
814
    project_notif.application_deny_notify(application)
815
    project_notif.application_notify(application, "deny")
815 816

  
816 817

  
817 818
def check_conflicting_projects(application):
......
860 861
        project.resume(actor=request_user, reason="APPROVE")
861 862
    quotas.qh_sync_locked_users(members)
862 863
    logger.info("%s has been approved." % (application.log_display))
863
    project_notif.application_approve_notify(application)
864
    project_notif.application_notify(application, "approve")
864 865

  
865 866

  
866 867
def check_expiration(execute=False):
......
882 883
    quotas.qh_sync_project(project)
883 884
    logger.info("%s has been terminated." % (project))
884 885

  
885
    project_notif.project_termination_notify(project)
886
    project_notif.project_notify(project, "terminate")
886 887

  
887 888

  
888 889
def suspend(project_id, request_user=None, reason=None):
......
894 895
    quotas.qh_sync_project(project)
895 896
    logger.info("%s has been suspended." % (project))
896 897

  
897
    project_notif.project_suspension_notify(project)
898
    project_notif.project_notify(project, "suspend")
898 899

  
899 900

  
900 901
def unsuspend(project_id, request_user=None, reason=None):
......
908 909
    project.resume(actor=request_user, reason=reason)
909 910
    quotas.qh_sync_project(project)
910 911
    logger.info("%s has been unsuspended." % (project))
911
    project_notif.project_unsuspension_notify(project)
912
    project_notif.project_notify(project, "unsuspend")
912 913

  
913 914

  
914 915
def reinstate(project_id, request_user=None, reason=None):
......
924 925
    project.resume(actor=request_user, reason=reason)
925 926
    quotas.qh_sync_project(project)
926 927
    logger.info("%s has been reinstated" % (project))
927
    project_notif.project_reinstatement_notify(project)
928
    project_notif.project_notify(project, "reinstate")
928 929

  
929 930

  
930 931
def _partition_by(f, l):
b/snf-astakos-app/astakos/im/project_notif.py
79 79
        logger.error(e.message)
80 80

  
81 81

  
82
def membership_request_notify(project, requested_user):
83
    try:
84
        notification = build_notification(
85
            SENDER,
86
            [project.application.owner.email],
87
            _(messages.PROJECT_MEMBERSHIP_REQUEST_SUBJECT) % project.__dict__,
88
            template='im/projects/project_membership_request_notification.txt',
89
            dictionary={'object': project, 'user': requested_user.email})
90
        notification.send()
91
    except NotificationError, e:
92
        logger.error(e.message)
82
MEMBERSHIP_REQUEST_DATA = {
83
    "join": lambda p: (
84
        _(messages.PROJECT_MEMBERSHIP_REQUEST_SUBJECT) % p.__dict__,
85
        "im/projects/project_membership_request_notification.txt"),
86
    "leave": lambda p: (
87
        _(messages.PROJECT_MEMBERSHIP_LEAVE_REQUEST_SUBJECT) % p.__dict__,
88
        "im/projects/project_membership_leave_request_notification.txt"),
89
}
93 90

  
94 91

  
95
def membership_leave_request_notify(project, requested_user):
96
    template = 'im/projects/project_membership_leave_request_notification.txt'
92
def membership_request_notify(project, requested_user, action):
93
    subject, template = MEMBERSHIP_REQUEST_DATA[action](project)
97 94
    try:
98
        notification = build_notification(
99
            SENDER,
100
            [project.application.owner.email],
101
            _(messages.PROJECT_MEMBERSHIP_LEAVE_REQUEST_SUBJECT) %
102
            project.__dict__,
95
        build_notification(
96
            SENDER, [project.application.owner.email], subject,
103 97
            template=template,
104
            dictionary={'object': project, 'user': requested_user.email})
105
        notification.send()
106
    except NotificationError, e:
107
        logger.error(e.message)
108

  
109

  
110
def application_submit_notify(application):
111
    try:
112
        notification = build_notification(
113
            SENDER, NOTIFY_RECIPIENTS,
114
            _(messages.PROJECT_CREATION_SUBJECT) % application.__dict__,
115
            template='im/projects/project_creation_notification.txt',
116
            dictionary={'object': application})
117
        notification.send()
118
    except NotificationError, e:
119
        logger.error(e.message)
120

  
121

  
122
def application_deny_notify(application):
123
    try:
124
        notification = build_notification(
125
            SENDER,
126
            [application.owner.email],
127
            _(messages.PROJECT_DENIED_SUBJECT) % application.__dict__,
128
            template='im/projects/project_denial_notification.txt',
129
            dictionary={'object': application})
130
        notification.send()
131
    except NotificationError, e:
132
        logger.error(e.message)
133

  
134

  
135
def application_approve_notify(application):
136
    try:
137
        notification = build_notification(
138
            SENDER,
139
            [application.owner.email],
140
            _(messages.PROJECT_APPROVED_SUBJECT) % application.__dict__,
141
            template='im/projects/project_approval_notification.txt',
142
            dictionary={'object': application})
143
        notification.send()
98
            dictionary={'object': project, 'user': requested_user.email}
99
        ).send()
144 100
    except NotificationError, e:
145 101
        logger.error(e.message)
146 102

  
147 103

  
148
def project_termination_notify(project):
149
    app = project.application
150
    try:
151
        build_notification(
152
            SENDER,
153
            [project.application.owner.email],
154
            _(messages.PROJECT_TERMINATION_SUBJECT) % app.__dict__,
155
            template='im/projects/project_termination_notification.txt',
156
            dictionary={'object': project}
157
        ).send()
158
    except NotificationError, e:
159
        logger.error(e.message)
104
APPLICATION_DATA = {
105
    "submit": lambda a: (
106
        NOTIFY_RECIPIENTS,
107
        _(messages.PROJECT_CREATION_SUBJECT) % a.__dict__,
108
        "im/projects/project_creation_notification.txt"),
109
    "deny": lambda a: (
110
        [a.owner.email],
111
        _(messages.PROJECT_DENIED_SUBJECT) % a.__dict__,
112
        "im/projects/project_denial_notification.txt"),
113
    "approve": lambda a: (
114
        [a.owner.email],
115
        _(messages.PROJECT_APPROVED_SUBJECT) % a.__dict__,
116
        "im/projects/project_approval_notification.txt"),
117
}
160 118

  
161 119

  
162
def project_suspension_notify(project):
120
def application_notify(application, action):
121
    recipients, subject, template = APPLICATION_DATA[action](application)
163 122
    try:
164 123
        build_notification(
165
            SENDER,
166
            [project.application.owner.email],
167
            _(messages.PROJECT_SUSPENSION_SUBJECT) % project.__dict__,
168
            template='im/projects/project_suspension_notification.txt',
169
            dictionary={'object': project}
124
            SENDER, recipients, subject,
125
            template=template,
126
            dictionary={'object': application}
170 127
        ).send()
171 128
    except NotificationError, e:
172 129
        logger.error(e.message)
173 130

  
174 131

  
175
def project_unsuspension_notify(project):
176
    try:
177
        build_notification(
178
            SENDER,
179
            [project.application.owner.email],
180
            _(messages.PROJECT_UNSUSPENSION_SUBJECT) % project.__dict__,
181
            template='im/projects/project_unsuspension_notification.txt',
182
            dictionary={'object': project}
183
        ).send()
184
    except NotificationError, e:
185
        logger.error(e.message)
132
PROJECT_DATA = {
133
    "terminate": lambda p: (
134
        _(messages.PROJECT_TERMINATION_SUBJECT) % p.application.__dict__,
135
        "im/projects/project_termination_notification.txt"),
136
    "reinstate": lambda p: (
137
        _(messages.PROJECT_REINSTATEMENT_SUBJECT) % p.__dict__,
138
        "im/projects/project_reinstatement_notification.txt"),
139
    "suspend": lambda p: (
140
        _(messages.PROJECT_SUSPENSION_SUBJECT) % p.__dict__,
141
        "im/projects/project_suspension_notification.txt"),
142
    "unsuspend": lambda p: (
143
        _(messages.PROJECT_UNSUSPENSION_SUBJECT) % p.__dict__,
144
        "im/projects/project_unsuspension_notification.txt"),
145
}
186 146

  
187 147

  
188
def project_reinstatement_notify(project):
148
def project_notify(project, action):
149
    subject, template = PROJECT_DATA[action](project)
189 150
    try:
190 151
        build_notification(
191
            SENDER,
192
            [project.application.owner.email],
193
            _(messages.PROJECT_REINSTATEMENT_SUBJECT) % project.__dict__,
194
            template='im/projects/project_reinstatement_notification.txt',
152
            SENDER, [project.application.owner.email], subject,
153
            template=template,
195 154
            dictionary={'object': project}
196 155
        ).send()
197 156
    except NotificationError, e:

Also available in: Unified diff