From 75410db7528c796bb01fd189b04e3ac59b4586ac Mon Sep 17 00:00:00 2001 From: Arona Jones Date: Mon, 13 Sep 2021 00:49:02 +0100 Subject: [PATCH] Refactor is_supervisor --- training/models.py | 12 +++++++----- training/templates/trainee_detail.html | 14 ++++++++------ training/views.py | 1 + 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/training/models.py b/training/models.py index 7de1ec1e..b03c7863 100644 --- a/training/models.py +++ b/training/models.py @@ -10,13 +10,15 @@ class Trainee(Profile): class Meta: proxy = True + def level_qualifications(self, only_confirmed=False): + levels = self.levels.all() + if only_confirmed: + levels = levels.filter(confirmed_on__isnull=False) + return levels.select_related('level') + @property def is_supervisor(self): - # FIXME Efficiency - for level_qualification in self.levels.select_related('level').all(): - if level_qualification.confirmed_on is not None and level_qualification.level.level >= TrainingLevel.SUPERVISOR: - return True - return False + return self.level_qualifications(True).filter(level__gte=TrainingLevel.SUPERVISOR).exists() def get_records_of_depth(self, depth): return self.qualifications_obtained.filter(depth=depth).select_related('item', 'trainee', 'supervisor') diff --git a/training/templates/trainee_detail.html b/training/templates/trainee_detail.html index 9a3e2459..15bcf89c 100644 --- a/training/templates/trainee_detail.html +++ b/training/templates/trainee_detail.html @@ -48,10 +48,7 @@ Add New Training Record - - Log External Training - - View Detailed Record
+ View Detailed Record
@@ -86,14 +83,16 @@
{% endif %} + {% empty %} +

No progress in any levels yet...did someone forget to fill out the paperwork?

{% endfor %}

Training Items

- -
+ {% for category in categories %} + {% if forloop.first or forloop.counter|divisibleby:3 %}
{% endif %}

{{ category }}

@@ -101,9 +100,12 @@ {% if q.item.category == category %}
  • {{q.item}} ({{q.date}})
  • {% endif %} + {% empty %} +
  • None yet...
  • {% endfor %}
    + {% if forloop.counter|add:"1"|divisibleby:3 %}
    {% endif %} {% endfor %}
    diff --git a/training/views.py b/training/views.py index 56eb0c18..81dfc314 100644 --- a/training/views.py +++ b/training/views.py @@ -29,6 +29,7 @@ class TraineeDetail(views.ProfileDetail, ModalURLMixin): context = super(TraineeDetail, self).get_context_data(**kwargs) context["page_title"] = "{}'s Training Record".format(self.object.first_name + " " + self.object.last_name) # TODO Filter this to levels the user has + # context["completed_levels"] = context["levels"] = models.TrainingLevel.objects.all() context["categories"] = models.TrainingCategory.objects.all().prefetch_related('items') choices = models.TrainingItemQualification.CHOICES