forked from beba/foerderbarometer
send decision mails on grant
This commit is contained in:
parent
76ba63002d
commit
e9b60d7205
|
|
@ -1,9 +1,11 @@
|
|||
import csv
|
||||
|
||||
from django.contrib import admin
|
||||
from django.db import models
|
||||
from django.db import models, transaction
|
||||
from django.http import HttpResponse
|
||||
|
||||
from input.utils.mail import send_decision_mail, send_staff_decision_mail
|
||||
|
||||
from .forms import BaseProjectForm
|
||||
from .models import (
|
||||
Account,
|
||||
|
|
@ -22,6 +24,7 @@ from .models import (
|
|||
BusinessCard,
|
||||
List,
|
||||
Literature,
|
||||
TYPE_PROJ,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -100,8 +103,7 @@ class ProjectAdminForm(BaseProjectForm):
|
|||
return cleaned_data
|
||||
|
||||
|
||||
@admin.register(Project)
|
||||
class ProjectAdmin(admin.ModelAdmin):
|
||||
class BaseProjectAdmin(admin.ModelAdmin):
|
||||
save_as = True
|
||||
form = ProjectAdminForm
|
||||
search_fields = ('name', 'pid','finance_id', 'realname', 'start', 'end', 'participants_estimated', 'participants_real', 'cost', 'status', 'end_quartal')
|
||||
|
|
@ -158,19 +160,39 @@ class ProjectAdmin(admin.ModelAdmin):
|
|||
class Media:
|
||||
js = ('dropdown/js/otrs_link.js',)
|
||||
|
||||
granted = True
|
||||
granted: bool
|
||||
|
||||
def get_queryset(self, request):
|
||||
return super().get_queryset(request).filter(granted=self.granted)
|
||||
|
||||
|
||||
@admin.register(Project)
|
||||
class ProjectAdmin(BaseProjectAdmin):
|
||||
granted = True
|
||||
|
||||
|
||||
@admin.register(ProjectRequest)
|
||||
class ProjectRequestAdmin(ProjectAdmin):
|
||||
class ProjectRequestAdmin(BaseProjectAdmin):
|
||||
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: self.send_decision_mails(obj))
|
||||
|
||||
return obj.granted
|
||||
|
||||
@staticmethod
|
||||
def send_decision_mails(obj):
|
||||
send_decision_mail(obj, TYPE_PROJ, obj.granted)
|
||||
send_staff_decision_mail(obj, TYPE_PROJ, obj.granted)
|
||||
|
||||
|
||||
@admin.register(ProjectDeclined)
|
||||
class ProjectDeclinedAdmin(ProjectAdmin):
|
||||
class ProjectDeclinedAdmin(BaseProjectAdmin):
|
||||
granted = False
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ def _type_labels(choice: str):
|
|||
Returns (HTML label, plain text label).
|
||||
"""
|
||||
html = TYPE_CHOICES.get(choice, choice)
|
||||
plain = strip_tags(str(html))
|
||||
plain = strip_tags(html)
|
||||
return html, plain
|
||||
|
||||
|
||||
|
|
@ -35,8 +35,8 @@ def _decision_context(obj, choice_code: str) -> dict:
|
|||
return {
|
||||
'data': {
|
||||
'realname': realname,
|
||||
'typestring': type_html,
|
||||
'typestring_plain': type_plain,
|
||||
'type_label': type_html,
|
||||
'type_label_plain': type_plain,
|
||||
'name': getattr(obj, 'name', None),
|
||||
},
|
||||
'project': obj,
|
||||
|
|
|
|||
Loading…
Reference in New Issue