From 081c33ebc8420dbc41046daf4bc991dce46595b0 Mon Sep 17 00:00:00 2001 From: Arona Jones Date: Mon, 13 Sep 2021 01:07:17 +0100 Subject: [PATCH] Various tweaks --- training/models.py | 5 ++++- training/templates/trainee_detail.html | 17 +++++++++++------ training/templates/trainee_list.html | 2 +- training/views.py | 10 ++++++---- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/training/models.py b/training/models.py index b03c7863..845daa9f 100644 --- a/training/models.py +++ b/training/models.py @@ -10,6 +10,9 @@ class Trainee(Profile): class Meta: proxy = True + def started_levels(self): + return [level for level in TrainingLevel.objects.all() if level.percentage_complete(self) > 0] + def level_qualifications(self, only_confirmed=False): levels = self.levels.all() if only_confirmed: @@ -219,7 +222,7 @@ class TrainingLevelQualification(models.Model): reversion_hide = True def __str__(self): - return "{} qualified as a {}".format(self.trainee, self.level) + return "{} is qualified as a {}".format(self.trainee, self.level) class Meta: unique_together = ["trainee", "level"] diff --git a/training/templates/trainee_detail.html b/training/templates/trainee_detail.html index 15bcf89c..0e7eac18 100644 --- a/training/templates/trainee_detail.html +++ b/training/templates/trainee_detail.html @@ -53,11 +53,19 @@

Training Levels

+ {% for level in completed_levels %} + {% if forloop.first %}
{% endif %} + + {% if forloop.last %}
{%endif%} + {% empty %} + No qualifications in any levels yet...did someone forget to fill out the paperwork? + {% endfor %}
- {% for level in levels %} + {% for level in started_levels %} {% percentage_complete level object as completion %} - {% if completion > 0 %} -
+

{{ level }}

{{ level.description|truncatewords:30 }}

@@ -82,9 +90,6 @@ {% endif %}
- {% endif %} - {% empty %} -

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

{% endfor %}
diff --git a/training/templates/trainee_list.html b/training/templates/trainee_list.html index 70afbf0a..4e3d6f65 100644 --- a/training/templates/trainee_list.html +++ b/training/templates/trainee_list.html @@ -22,7 +22,7 @@ {% for object in object_list %} - {{ object.name }} {% if request.user.pk == object.pk %}{%endif%} + {{ object.name }} {% if request.user.pk == object.pk %}{%endif%} {{ object.is_supervisor|yesno|title }} {{ object.qualifications_obtained.all|length }} diff --git a/training/views.py b/training/views.py index 81dfc314..e4176de0 100644 --- a/training/views.py +++ b/training/views.py @@ -27,10 +27,12 @@ class TraineeDetail(views.ProfileDetail, ModalURLMixin): def get_context_data(self, **kwargs): 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() + if self.request.user.pk == self.object.pk: + context["page_title"] = "Your Training Record" + else: + context["page_title"] = "{}'s Training Record".format(self.object.first_name + " " + self.object.last_name) + context["started_levels"] = self.object.started_levels() + context["completed_levels"] = self.object.level_qualifications() context["categories"] = models.TrainingCategory.objects.all().prefetch_related('items') choices = models.TrainingItemQualification.CHOICES context["depths"] = choices