Significant improvements to level list

Added search
Ordered by qualification count
Added display for technician qualifications
This commit is contained in:
2021-12-27 14:59:30 +00:00
parent aa8be6a6d0
commit 3b5b3b84d4
5 changed files with 44 additions and 7 deletions

View File

@@ -79,7 +79,7 @@
}); });
$(function () { $(function () {
$('[data-toggle="tooltip"]').tooltip(); $('[data-toggle="tooltip"]').tooltip();
}) });
</script> </script>
{% endblock %} {% endblock %}

View File

@@ -4,6 +4,8 @@ from RIGS.models import RevisionMixin, Profile
from reversion import revisions as reversion from reversion import revisions as reversion
from django.urls import reverse from django.urls import reverse
from django.utils.safestring import SafeData, mark_safe
# 'shim' overtop the profile model to neatly contain all training related fields etc # 'shim' overtop the profile model to neatly contain all training related fields etc
@@ -251,6 +253,14 @@ class TrainingLevelQualification(models.Model, RevisionMixin):
reversion_hide = True reversion_hide = True
@property
def get_icon(self):
if self.level.icon is not None:
icon = "<span class='fas fa-{}'></span>".format(self.level.icon)
else:
icon = "".join([w[0] for w in str(self.level).split()])
return mark_safe("<span class='badge badge-{} badge-pill' data-toggle='tooltip' title='{}'>{}</span>".format(self.level.department_colour, self.level, icon))
def __str__(self): def __str__(self):
if self.level.is_common_competencies: if self.level.is_common_competencies:
return "{} is qualified in the {}".format(self.trainee, self.level) return "{} is qualified in the {}".format(self.trainee, self.level)

View File

@@ -5,9 +5,19 @@
{% load paginator from filters %} {% load paginator from filters %}
{% load linkornone from filters %} {% load linkornone from filters %}
{% load button from filters %} {% load button from filters %}
{% load get_levels_of_depth from tags %}
{% block js %}
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip();
});
</script>
{% endblock %}
{% block content %} {% block content %}
<div class="row"> {% include 'partials/list_search.html' %}
<div class="row pt-2">
<div class="col"> <div class="col">
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped"> <table class="table table-striped">
@@ -15,6 +25,7 @@
<tr> <tr>
<th scope="col">Name</th> <th scope="col">Name</th>
<th>Van Driver?</th> <th>Van Driver?</th>
<th>Technician?</th>
<th>Supervisor?</th> <th>Supervisor?</th>
<th>Qualification Count</th> <th>Qualification Count</th>
<th></th> <th></th>
@@ -25,9 +36,10 @@
<tr id="row_item"> <tr id="row_item">
<th scope="row" class="align-middle" id="cell_name"><a href="{% url 'trainee_detail' object.pk %}">{{ object.name }} {% if request.user.pk == object.pk %}<span class="fas fa-user text-success"></span>{%endif%}</a></th> <th scope="row" class="align-middle" id="cell_name"><a href="{% url 'trainee_detail' object.pk %}">{{ object.name }} {% if request.user.pk == object.pk %}<span class="fas fa-user text-success"></span>{%endif%}</a></th>
<td {% if object.is_driver %}class="table-success"{%endif%}>{{ object.is_driver|yesno|title }}</td> <td {% if object.is_driver %}class="table-success"{%endif%}>{{ object.is_driver|yesno|title }}</td>
<td>{% for level in object|get_levels_of_depth:1 %}{{ level.get_icon }}{%empty%}No{%endfor%}</td>
<td {% if object.is_supervisor %}class="table-success"{%endif%}>{{ object.is_supervisor|yesno|title }}</td> <td {% if object.is_supervisor %}class="table-success"{%endif%}>{{ object.is_supervisor|yesno|title }}</td>
<td>{{ object.qualifications_obtained.all|length }}</td> <td>{{ object.num_qualifications }}</td>
<td> <td style="white-space: nowrap">
<a class="btn btn-info" href="{% url 'trainee_detail' pk=object.pk %}"><span class="fas fa-eye"></span> View Training Record</a> <a class="btn btn-info" href="{% url 'trainee_detail' pk=object.pk %}"><span class="fas fa-eye"></span> View Training Record</a>
<a href="{% url 'trainee_item_detail' pk=object.pk %}" class="btn btn-info"><span class="fas fa-info-circle"></span> View Detailed Record</a> <a href="{% url 'trainee_item_detail' pk=object.pk %}" class="btn btn-info"><span class="fas fa-info-circle"></span> View Detailed Record</a>
</td> </td>

View File

@@ -27,7 +27,10 @@ def percentage_complete(level, user):
def colour_from_depth(depth): def colour_from_depth(depth):
return models.TrainingItemQualification.get_colour_from_depth(depth) return models.TrainingItemQualification.get_colour_from_depth(depth)
@register.filter @register.filter
def get_supervisor(tech): def get_supervisor(tech):
return models.TrainingLevel.objects.get(department=tech.department, level=models.TrainingLevel.SUPERVISOR) return models.TrainingLevel.objects.get(department=tech.department, level=models.TrainingLevel.SUPERVISOR)
@register.filter
def get_levels_of_depth(trainee, level):
return trainee.level_qualifications(True).filter(level__level=level)

View File

@@ -7,6 +7,7 @@ from PyRIGS.views import OEmbedView, is_ajax, ModalURLMixin
from training import models, forms from training import models, forms
from django.utils import timezone from django.utils import timezone
from django.db import transaction from django.db import transaction
from django.db.models import Q, Count
from users import views from users import views
@@ -86,10 +87,21 @@ class TraineeList(generic.ListView):
model = models.Trainee model = models.Trainee
template_name = 'trainee_list.html' template_name = 'trainee_list.html'
paginate_by = 25 paginate_by = 25
ordering = ['qualifications_obtained']
def get_queryset(self): def get_queryset(self):
return self.model.objects.prefetch_related('levels', 'qualifications_obtained') q = self.request.GET.get('q', "")
filter = Q(first_name__icontains=q) | Q(last_name__icontains=q) | Q(initials__icontains=q)
# try and parse an int
try:
val = int(q)
filter = filter | Q(pk=val)
except: # noqa
# not an integer
pass
return self.model.objects.filter(filter).annotate(num_qualifications=Count('qualifications_obtained')).order_by('-num_qualifications').prefetch_related('levels', 'qualifications_obtained')
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)