From 9590c2066d1bb8532188a9327cfab9ec4ca47846 Mon Sep 17 00:00:00 2001 From: FreneticScribbler Date: Thu, 19 Aug 2021 16:19:46 +0100 Subject: [PATCH] Validate that only supervisors may be supervisors --- training/forms.py | 6 ++++-- training/models.py | 1 + training/templates/trainee_detail.html | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/training/forms.py b/training/forms.py index 78cb92f5..cc52f889 100644 --- a/training/forms.py +++ b/training/forms.py @@ -19,7 +19,7 @@ class QualificationForm(forms.ModelForm): super(QualificationForm, self).__init__(*args, **kwargs) self.fields['trainee'].initial = Profile.objects.get(pk=pk) self.fields['date'].initial = date.today() - + def clean_date(self): date = self.cleaned_data['date'] if date > date.today(): @@ -30,7 +30,9 @@ class QualificationForm(forms.ModelForm): supervisor = self.cleaned_data['supervisor'] if supervisor.pk == self.cleaned_data['trainee'].pk: raise forms.ValidationError('One may not supervise oneself...') - return supervisor # TODO also confirm that the supervisor is a Supervisor + if not supervisor.is_supervisor: + raise forms.ValidationError('Selected supervisor must actually *be* a supervisor...') + return supervisor class RequirementForm(forms.ModelForm): depth = forms.ChoiceField(choices=models.TrainingItemQualification.CHOICES) diff --git a/training/models.py b/training/models.py index 78508e0f..6307d61a 100644 --- a/training/models.py +++ b/training/models.py @@ -10,6 +10,7 @@ class Trainee(Profile): @property def is_supervisor(self): + # FIXME Efficiency for level_qualification in self.levels.select_related('level').all(): if confirmed_on is not None and level_qualification.level.level >= TrainingLevel.SUPERVISOR: return True diff --git a/training/templates/trainee_detail.html b/training/templates/trainee_detail.html index 0dd0c3e7..f29ce12f 100644 --- a/training/templates/trainee_detail.html +++ b/training/templates/trainee_detail.html @@ -12,7 +12,7 @@

Training Levels

-

Technical Assistant is conferred automatically when the item requirements are met. Technician status is also automatic, but notification of status should be made at the next general meeting, at which point 'approval' should be granted on the system. Supervisor status is not automatic and until signed off at a general meeting, does not count.Correct as of 7th July 2021, check the Training Policy.

+
{% for level in levels %}
@@ -21,10 +21,10 @@

{{ level.description|truncatewords:30 }}

{% percentage_complete level object as completion %} - +
{{completion}}% complete
- +