forked from beba/foerderbarometer
WM-13: removed decision mails
This commit is contained in:
parent
ee987d73c2
commit
771819af0e
|
|
@ -1,11 +1,10 @@
|
||||||
import csv
|
import csv
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.db import models, transaction
|
from django.db import models
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
|
||||||
from input.utils.list import reorder_value
|
from input.utils.list import reorder_value
|
||||||
from input.utils.mail import send_decision_mails
|
|
||||||
|
|
||||||
from .forms import BaseProjectForm
|
from .forms import BaseProjectForm
|
||||||
from .models import (
|
from .models import (
|
||||||
|
|
@ -174,16 +173,6 @@ class ProjectAdmin(BaseProjectAdmin):
|
||||||
class ProjectRequestAdmin(BaseProjectAdmin):
|
class ProjectRequestAdmin(BaseProjectAdmin):
|
||||||
granted = None
|
granted = None
|
||||||
|
|
||||||
def save_model(self, request, obj: ProjectRequest, form: ProjectAdminForm, change: bool):
|
|
||||||
super().save_model(request, obj, form, change)
|
|
||||||
|
|
||||||
if obj.granted is None:
|
|
||||||
return None
|
|
||||||
|
|
||||||
transaction.on_commit(lambda: send_decision_mails(obj))
|
|
||||||
|
|
||||||
return obj.granted
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(ProjectDeclined)
|
@admin.register(ProjectDeclined)
|
||||||
class ProjectDeclinedAdmin(BaseProjectAdmin):
|
class ProjectDeclinedAdmin(BaseProjectAdmin):
|
||||||
|
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
<html>
|
|
||||||
<body>
|
|
||||||
<p>Hallo {{ data.realname }},</p>
|
|
||||||
|
|
||||||
<p>Deine Förderanfrage {{project.name}} wurde leider abgelehnt.</p>
|
|
||||||
|
|
||||||
<p>Fragen? <a href="mailto:community@wikimedia.de">community@wikimedia.de</a></p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
Hallo {{ data.realname }},
|
|
||||||
|
|
||||||
deine Förderanfrage {{project.name}} wurde leider abgelehnt.
|
|
||||||
|
|
||||||
Fragen? community@wikimedia.de
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
<html>
|
|
||||||
<body>
|
|
||||||
<p>Hallo Team Community-Konferenzen & Förderung,</p>
|
|
||||||
|
|
||||||
<p>Die Förderanfrage {{project.name}} von {{ data.realname }} wurde abgelehnt.</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
Hallo Team Community-Konferenzen & Förderung,
|
|
||||||
|
|
||||||
die Förderanfrage {{project.name}} von {{ data.realname }} wurde abgelehnt.
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
<html>
|
|
||||||
<body>
|
|
||||||
<p>Hallo {{ data.realname }},</p>
|
|
||||||
|
|
||||||
<p>Deine Förderanfrage {{project.name}} wurde bewilligt.</p>
|
|
||||||
|
|
||||||
<p>Das Team Community-Konferenzen & Förderung meldet sich bald bei dir.<br>
|
|
||||||
Fragen? <a href="mailto:community@wikimedia.de">community@wikimedia.de</a></p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
Hallo {{ data.realname }},
|
|
||||||
|
|
||||||
deine Förderanfrage {{project.name}} wurde bewilligt.
|
|
||||||
|
|
||||||
Das Team Community-Konferenzen & Förderung meldet sich bald bei dir.
|
|
||||||
Fragen? community@wikimedia.de
|
|
||||||
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
<html>
|
|
||||||
<body>
|
|
||||||
<p>Hallo Team Community-Konferenzen & Förderung,</p>
|
|
||||||
|
|
||||||
<p>Die Förderanfrage {{project.name}} von {{ data.realname }} wurde bewilligt.</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
Hallo Team Community-Konferenzen & Förderung,
|
|
||||||
|
|
||||||
die Förderanfrage {{project.name}} von {{ data.realname }} wurde bewilligt.
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.core import mail
|
|
||||||
from django.forms import model_to_dict
|
from django.forms import model_to_dict
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
|
|
@ -109,7 +108,4 @@ class AdminTestCase(TestCase):
|
||||||
if data[key] is None:
|
if data[key] is None:
|
||||||
data.pop(key)
|
data.pop(key)
|
||||||
|
|
||||||
with self.captureOnCommitCallbacks(execute=True):
|
|
||||||
request(self, url, expected_url=expected_url, data=data)
|
request(self, url, expected_url=expected_url, data=data)
|
||||||
|
|
||||||
self.assertEqual(len(mail.outbox), 2)
|
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,6 @@ __all__ = [
|
||||||
'build_email',
|
'build_email',
|
||||||
'send_email',
|
'send_email',
|
||||||
'collect_and_attach',
|
'collect_and_attach',
|
||||||
'send_applicant_decision_mail',
|
|
||||||
'send_staff_decision_mail',
|
|
||||||
'send_decision_mails',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -35,49 +32,3 @@ def build_email(template_name: str, context: dict, subject: str, *recipients: st
|
||||||
|
|
||||||
def send_email(template_name: str, context: dict, subject: str, *recipients: str, fail_silently=False, **kwargs):
|
def send_email(template_name: str, context: dict, subject: str, *recipients: str, fail_silently=False, **kwargs):
|
||||||
return build_email(template_name, context, subject, *recipients, **kwargs).send(fail_silently)
|
return build_email(template_name, context, subject, *recipients, **kwargs).send(fail_silently)
|
||||||
|
|
||||||
|
|
||||||
def get_decision_mail_context(obj: Project):
|
|
||||||
"""
|
|
||||||
Build a minimal, consistent context for decision mails (applicant & staff).
|
|
||||||
"""
|
|
||||||
|
|
||||||
return {
|
|
||||||
'project': obj,
|
|
||||||
'data': {
|
|
||||||
'realname': obj.realname or obj.email,
|
|
||||||
'name': obj.name,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def send_base_decision_mail(obj: Project, scope: str, subject: str, recipient: str):
|
|
||||||
context = get_decision_mail_context(obj)
|
|
||||||
decision = 'granted' if obj.granted else 'denied'
|
|
||||||
decision_label = 'bewilligt' if obj.granted else 'abgelehnt'
|
|
||||||
subject = subject.format(name=obj.name, decision=decision_label)
|
|
||||||
|
|
||||||
return send_email(f'approval_{decision}_{scope}', context, subject, recipient)
|
|
||||||
|
|
||||||
|
|
||||||
def send_applicant_decision_mail(obj: Project):
|
|
||||||
"""
|
|
||||||
Send a decision email to the applicant after manual approval/denial.
|
|
||||||
"""
|
|
||||||
|
|
||||||
if recipient := obj.email:
|
|
||||||
return send_base_decision_mail(obj, 'applicant', 'Deine Förderanfrage „{name}“ – {decision}', recipient)
|
|
||||||
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
def send_staff_decision_mail(obj: Project):
|
|
||||||
"""
|
|
||||||
Send a decision email to the internal team (staff) after approval/denial.
|
|
||||||
"""
|
|
||||||
|
|
||||||
return send_base_decision_mail(obj, 'staff', 'Entscheidung: {name} ({decision})', settings.IF_EMAIL)
|
|
||||||
|
|
||||||
|
|
||||||
def send_decision_mails(obj: Project):
|
|
||||||
return send_applicant_decision_mail(obj) + send_staff_decision_mail(obj)
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue