diff --git a/training/forms.py b/training/forms.py index 7fab1883..78cb92f5 100644 --- a/training/forms.py +++ b/training/forms.py @@ -16,13 +16,21 @@ class QualificationForm(forms.ModelForm): def __init__(self, *args, **kwargs): pk = kwargs.pop('pk', None) - super().__init__() + 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(): - raise ValidationError('Qualification date may not be in the future') + raise forms.ValidationError('Qualification date may not be in the future') + return date + + def clean_supervisor(self): + 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 class RequirementForm(forms.ModelForm): depth = forms.ChoiceField(choices=models.TrainingItemQualification.CHOICES) @@ -33,5 +41,5 @@ class RequirementForm(forms.ModelForm): def __init__(self, *args, **kwargs): pk = kwargs.pop('pk', None) - super().__init__() + super(RequirementForm, self).__init__(*args, **kwargs) self.fields['level'].initial = models.TrainingLevel.objects.get(pk=pk) diff --git a/training/migrations/0003_auto_20210716_0150.py b/training/migrations/0003_auto_20210716_0150.py new file mode 100644 index 00000000..e9c32dab --- /dev/null +++ b/training/migrations/0003_auto_20210716_0150.py @@ -0,0 +1,24 @@ +# Generated by Django 3.1.5 on 2021-07-16 00:50 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('training', '0002_auto_20210706_0053'), + ] + + operations = [ + migrations.AlterField( + model_name='traininglevelqualification', + name='confirmed_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.RESTRICT, related_name='confirmer', to='training.trainee'), + ), + migrations.AlterField( + model_name='traininglevelqualification', + name='confirmed_on', + field=models.DateTimeField(null=True), + ), + ] diff --git a/training/models.py b/training/models.py index 3f792f97..1b94d982 100644 --- a/training/models.py +++ b/training/models.py @@ -26,6 +26,9 @@ class TrainingCategory(models.Model): reference_number = models.CharField(max_length=3) name = models.CharField(max_length=50) + def __str__(self): + return "{}. {}".format(self.reference_number, self.name) + class Meta: verbose_name_plural = 'Training Categories' @@ -67,9 +70,9 @@ class TrainingItemQualification(models.Model): def save(self, *args, **kwargs): super().save() - for level in TrainingLevel.models.all(): # Mm yes efficiency + for level in TrainingLevel.objects.all(): # Mm yes efficiency if level.user_has_requirements(self.trainee): - level_qualification = models.TrainingLevelQualification.create(trainee=self.trainee, level=level) + level_qualification = TrainingLevelQualification.objects.create(trainee=self.trainee, level=level) # Levels @@ -118,8 +121,7 @@ class TrainingLevel(models.Model, RevisionMixin): return 0 def user_has_requirements(self, user): - return all(TrainingItem.user_has_qualification(req.item, user, req.depth) for req in self.requirements.all()) - + return all(TrainingItem.user_has_qualification(req.item, user, req.depth) for req in self.requirements.all()) def __str__(self): if self.department is None: # 2TA diff --git a/training/templates/edit_training_record.html b/training/templates/edit_training_record.html index 389334c1..aa5699d4 100644 --- a/training/templates/edit_training_record.html +++ b/training/templates/edit_training_record.html @@ -2,6 +2,7 @@ {% load static %} {% load widget_tweaks %} +{% load button from filters %} {% block css %} {{ block.super }} @@ -23,26 +24,26 @@ {% if form.errors %} {% include 'form_errors.html' %} {% endif %} -
{% endblock %} diff --git a/training/templates/trainee_detail.html b/training/templates/trainee_detail.html index ac7117dd..2abd1df4 100644 --- a/training/templates/trainee_detail.html +++ b/training/templates/trainee_detail.html @@ -20,7 +20,7 @@{{ level.description|truncatewords:30 }}