From dbb9e3e530453c824508104a51036882968dddda Mon Sep 17 00:00:00 2001 From: FreneticScribbler Date: Sat, 9 Oct 2021 10:29:03 +0100 Subject: [PATCH] Add 'is van driver' to trainee list, haulage super doesn't count as a supervisor --- .../commands/generateSampleTrainingData.py | 2 +- training/models.py | 11 +++++-- training/templates/base_training.html | 17 +++++++--- training/templates/trainee_detail.html | 31 ++++++++----------- training/templates/trainee_list.html | 2 ++ 5 files changed, 36 insertions(+), 27 deletions(-) diff --git a/training/management/commands/generateSampleTrainingData.py b/training/management/commands/generateSampleTrainingData.py index 3498485a..1ed90708 100644 --- a/training/management/commands/generateSampleTrainingData.py +++ b/training/management/commands/generateSampleTrainingData.py @@ -90,4 +90,4 @@ class Command(BaseCommand): is_staff=True) supervisor.set_password('supervisor') supervisor.save() - models.TrainingLevelQualification.objects.create(trainee=supervisor, level=self.levels[-1], confirmed_on=timezone.now()) + models.TrainingLevelQualification.objects.create(trainee=supervisor, level=models.TrainingLevel.objects.filter(level__gte=models.TrainingLevel.SUPERVISOR).exclude(department=models.TrainingLevel.HAULAGE).first(), confirmed_on=timezone.now()) diff --git a/training/models.py b/training/models.py index 845daa9f..c858f7e7 100644 --- a/training/models.py +++ b/training/models.py @@ -16,12 +16,16 @@ class Trainee(Profile): def level_qualifications(self, only_confirmed=False): levels = self.levels.all() if only_confirmed: - levels = levels.filter(confirmed_on__isnull=False) + levels = levels.exclude(confirmed_on__isnull=True) return levels.select_related('level') @property def is_supervisor(self): - return self.level_qualifications(True).filter(level__gte=TrainingLevel.SUPERVISOR).exists() + return self.level_qualifications(True).filter(level__gte=TrainingLevel.SUPERVISOR).exclude(level__department=TrainingLevel.HAULAGE).exists() + + @property + def is_driver(self): + return self.level_qualifications(True).filter(level__department=TrainingLevel.HAULAGE).exists() def get_records_of_depth(self, depth): return self.qualifications_obtained.filter(depth=depth).select_related('item', 'trainee', 'supervisor') @@ -123,12 +127,13 @@ class TrainingLevel(models.Model, RevisionMixin): (TECHNICIAN, 'Technician'), (SUPERVISOR, 'Supervisor'), ) + HAULAGE = 4 DEPARTMENTS = ( (0, 'Sound'), (1, 'Lighting'), (2, 'Power'), (3, 'Rigging'), - (4, 'Haulage'), + (HAULAGE, 'Haulage'), ) department = models.IntegerField(choices=DEPARTMENTS, null=True) # N.B. Technical Assistant does not have a department level = models.IntegerField(choices=CHOICES) diff --git a/training/templates/base_training.html b/training/templates/base_training.html index 0640ca75..60e655c2 100644 --- a/training/templates/base_training.html +++ b/training/templates/base_training.html @@ -10,19 +10,26 @@ {% if user.is_authenticated %} - - - + {% endif %} {% endblock %} diff --git a/training/templates/trainee_detail.html b/training/templates/trainee_detail.html index 0e7eac18..968773f2 100644 --- a/training/templates/trainee_detail.html +++ b/training/templates/trainee_detail.html @@ -53,10 +53,21 @@

Training Levels

- {% for level in completed_levels %} + {% for qual in completed_levels %} {% if forloop.first %}
{% endif %}
-

{{ level }}

+

{{ qual }}

+
{% if forloop.last %}
{%endif%} {% empty %} @@ -73,22 +84,6 @@
{{completion}}% complete
- {% endfor %} diff --git a/training/templates/trainee_list.html b/training/templates/trainee_list.html index 4e3d6f65..147d3a8d 100644 --- a/training/templates/trainee_list.html +++ b/training/templates/trainee_list.html @@ -14,6 +14,7 @@ Name + Van Driver? Supervisor? Qualification Count @@ -23,6 +24,7 @@ {% for object in object_list %} {{ object.name }} {% if request.user.pk == object.pk %}{%endif%} + {{ object.is_driver|yesno|title }} {{ object.is_supervisor|yesno|title }} {{ object.qualifications_obtained.all|length }}