Validate that only supervisors may be supervisors

This commit is contained in:
2021-08-19 16:19:46 +01:00
parent 8b48b02ca7
commit 9590c2066d
3 changed files with 8 additions and 5 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -12,7 +12,7 @@
</div>
<div class="row mb-3">
<h2 class="col-12">Training Levels</h2>
<p>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 <em>not automatic</em> and until signed off at a general meeting, does not count.<sup>Correct as of 7th July 2021, check the Training Policy.</sup></p>
<div class="alert alert-info" role="alert">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 <em>not automatic</em> and until signed off at a general meeting, does not count.<sup>Correct as of 7th July 2021, check the Training Policy.</sup></div>
<div class="card-columns">
{% for level in levels %}
<div class="card my-3">
@@ -21,10 +21,10 @@
<p>{{ level.description|truncatewords:30 }}</p>
<div class="progress mb-2">
{% percentage_complete level object as completion %}
<div class="progress-bar progress-bar-striped" role="progressbar" style="width: {{completion}}%" aria-valuenow="{{completion}}" aria-valuemin="0" aria-valuemax="100">{{completion}}% complete</div>
</div>
<button class="btn btn-link p-0" type="button" data-toggle="collapse" data-target=".reqs_{{level.pk}}" aria-expanded="false" aria-controls="reqs_{{level.pk}}">
Requirements <span class="fas fa-caret-right reqs_{{level.pk}} collapse show"></span><span class="fas fa-caret-down collapse reqs_{{level.pk}}"></span>
</button>