Allow technicians to record training sessions (#664)

* Allow technicians to record training sessions

Add a per-item technician_can_train flag. Technicians in an item's department
who are passed out on a flagged item may log Training Started/Complete for it.

* Run linter
This commit is contained in:
Joe Banks
2026-10-03 16:10:13 +01:00
committed by GitHub
parent abfc394088
commit 435e6688e1
11 changed files with 191 additions and 8 deletions

View File

@@ -155,6 +155,7 @@ class AddQualification(generic.CreateView, ModalURLMixin):
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs["pk"] = self.kwargs["pk"]
kwargs["user"] = self.request.user
return kwargs
@@ -163,6 +164,17 @@ class EditQualification(generic.UpdateView, ModalURLMixin):
model = models.TrainingItemQualification
form_class = forms.QualificationForm
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs["user"] = self.request.user
return kwargs
def get_queryset(self):
queryset = super().get_queryset()
if not self.request.user.is_supervisor: # Technicians may only edit records they delivered
queryset = queryset.filter(supervisor=self.request.user.pk)
return queryset
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["depths"] = models.TrainingItemQualification.CHOICES
@@ -251,6 +263,11 @@ class SessionLog(generic.FormView):
form_class = forms.SessionLogForm
success_url = reverse_lazy("trainee_list")
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs["user"] = self.request.user
return kwargs
def form_valid(self, form, *args, **kwargs):
for trainee in form.cleaned_data.get("trainees", []):
for depth in models.TrainingItemQualification.CHOICES: