System for allowing certain TrainingCategories to be trained by certain levels, regardless of supervisor status

I.e. the haulage department, ref #482. As generic as I can make it I think.
This commit is contained in:
2022-01-25 13:04:26 +00:00
parent 15ab626593
commit 33754eed60
5 changed files with 34 additions and 6 deletions

View File

@@ -23,9 +23,13 @@ class QualificationForm(forms.ModelForm):
def clean_supervisor(self):
supervisor = self.cleaned_data['supervisor']
item = self.cleaned_data['item']
if supervisor.pk == self.cleaned_data['trainee'].pk:
raise forms.ValidationError('One may not supervise oneself...')
if not supervisor.is_supervisor:
if item.category.training_level:
if not supervisor.level_qualifications.filter(level=item.category.training_level):
raise forms.ValidationError('Selected supervising person is missing requisite training level to train in this department')
elif not supervisor.is_supervisor:
raise forms.ValidationError('Selected supervisor must actually *be* a supervisor...')
return supervisor