From c77c966e0e51abd7ec0c614ec9e34c4fbccf744e Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 29 May 2025 22:52:35 +0200 Subject: [PATCH] feat: auto select tutor as assignee --- ticketsystem/forms.py | 19 +++++- .../templates/ticketsystem/detail.html | 51 ++++++++++++--- .../templates/ticketsystem/ticket_form.html | 64 +++++++++++++++---- ticketsystem/views.py | 43 +++++++++---- 4 files changed, 143 insertions(+), 34 deletions(-) diff --git a/ticketsystem/forms.py b/ticketsystem/forms.py index 3d1c9ec..6b38809 100644 --- a/ticketsystem/forms.py +++ b/ticketsystem/forms.py @@ -1,5 +1,5 @@ from django import forms -from .models import Comment +from .models import Comment, Ticket class CommentForm(forms.ModelForm): @@ -11,3 +11,20 @@ class CommentForm(forms.ModelForm): attrs={"rows": 3, "placeholder": "Kommentar schreiben..."} ), } + + +class TicketForm(forms.ModelForm): + class Meta: + model = Ticket + fields = ["title", "description", "status", "priority", "course"] + + def save(self, commit=True): + ticket = super().save(commit=False) + + # Automatische Tutor-Zuweisung basierend auf dem ausgewählten Kurs + if ticket.course and ticket.course.tutor: + ticket.assigned_to = ticket.course.tutor + + if commit: + ticket.save() + return ticket \ No newline at end of file diff --git a/ticketsystem/templates/ticketsystem/detail.html b/ticketsystem/templates/ticketsystem/detail.html index cdedc6b..e3e264b 100644 --- a/ticketsystem/templates/ticketsystem/detail.html +++ b/ticketsystem/templates/ticketsystem/detail.html @@ -38,6 +38,7 @@
- - {% for user in form.assigned_to.field.queryset %} - - {% endfor %} - +
+ {% if ticket.assigned_to %}{{ ticket.assigned_to.username }}{% else %}Niemand zugewiesen{% endif %} +
+

Wird automatisch basierend auf dem ausgewählten Kurs zugewiesen

{% if view.can_edit %}