send decision mails on grant

This commit is contained in:
Oliver Zander 2025-10-17 14:15:56 +02:00
parent 76ba63002d
commit e9b60d7205
2 changed files with 31 additions and 9 deletions

View File

@ -1,9 +1,11 @@
import csv import csv
from django.contrib import admin from django.contrib import admin
from django.db import models from django.db import models, transaction
from django.http import HttpResponse from django.http import HttpResponse
from input.utils.mail import send_decision_mail, send_staff_decision_mail
from .forms import BaseProjectForm from .forms import BaseProjectForm
from .models import ( from .models import (
Account, Account,
@ -22,6 +24,7 @@ from .models import (
BusinessCard, BusinessCard,
List, List,
Literature, Literature,
TYPE_PROJ,
) )
@ -100,8 +103,7 @@ class ProjectAdminForm(BaseProjectForm):
return cleaned_data return cleaned_data
@admin.register(Project) class BaseProjectAdmin(admin.ModelAdmin):
class ProjectAdmin(admin.ModelAdmin):
save_as = True save_as = True
form = ProjectAdminForm form = ProjectAdminForm
search_fields = ('name', 'pid','finance_id', 'realname', 'start', 'end', 'participants_estimated', 'participants_real', 'cost', 'status', 'end_quartal') 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: class Media:
js = ('dropdown/js/otrs_link.js',) js = ('dropdown/js/otrs_link.js',)
granted = True granted: bool
def get_queryset(self, request): def get_queryset(self, request):
return super().get_queryset(request).filter(granted=self.granted) return super().get_queryset(request).filter(granted=self.granted)
@admin.register(Project)
class ProjectAdmin(BaseProjectAdmin):
granted = True
@admin.register(ProjectRequest) @admin.register(ProjectRequest)
class ProjectRequestAdmin(ProjectAdmin): 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: 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) @admin.register(ProjectDeclined)
class ProjectDeclinedAdmin(ProjectAdmin): class ProjectDeclinedAdmin(BaseProjectAdmin):
granted = False granted = False

View File

@ -21,7 +21,7 @@ def _type_labels(choice: str):
Returns (HTML label, plain text label). Returns (HTML label, plain text label).
""" """
html = TYPE_CHOICES.get(choice, choice) html = TYPE_CHOICES.get(choice, choice)
plain = strip_tags(str(html)) plain = strip_tags(html)
return html, plain return html, plain
@ -35,8 +35,8 @@ def _decision_context(obj, choice_code: str) -> dict:
return { return {
'data': { 'data': {
'realname': realname, 'realname': realname,
'typestring': type_html, 'type_label': type_html,
'typestring_plain': type_plain, 'type_label_plain': type_plain,
'name': getattr(obj, 'name', None), 'name': getattr(obj, 'name', None),
}, },
'project': obj, 'project': obj,