Various fixes

This commit is contained in:
2022-01-02 19:15:44 +00:00
parent 2767777d0e
commit c6157d3e2b
5 changed files with 26 additions and 14 deletions

View File

@@ -16,9 +16,17 @@ class Trainee(Profile, RevisionMixin):
def started_levels(self):
return [level for level in TrainingLevel.objects.all() if level.percentage_complete(self) > 0 and level.pk not in self.level_qualifications.values_list('level', flat=True)]
@property
def is_technician(self):
return self.level_qualifications.exclude(confirmed_on=None).select_related('level') \
.filter(level__level=TrainingLevel.TECHNICIAN) \
.exclude(level__department=TrainingLevel.HAULAGE) \
.exclude(level__department__isnull=True).exists()
@property
def is_supervisor(self):
return self.level_qualifications.all().exclude(confirmed_on=None).select_related('level') \
return self.level_qualifications.exclude(confirmed_on=None).select_related('level') \
.filter(level__level__gte=TrainingLevel.SUPERVISOR) \
.exclude(level__department=TrainingLevel.HAULAGE) \
.exclude(level__department__isnull=True).exists()
@@ -66,7 +74,7 @@ class TrainingItem(models.Model):
@staticmethod
def user_has_qualification(item, user, depth):
return user.qualifications_obtained.values('item', 'depth').filter(item=item, depth__gte=depth).exists()
return user.qualifications_obtained.only('item', 'depth').filter(item=item, depth__gte=depth).exists()
class Meta:
unique_together = ["reference_number", "active", "category"]
@@ -211,6 +219,14 @@ class TrainingLevel(models.Model, RevisionMixin):
def get_absolute_url(self):
return reverse('level_detail', kwargs={'pk': self.pk})
@property
def get_icon(self):
if self.icon is not None:
icon = "<span class='fas fa-{}'></span>".format(self.icon)
else:
icon = "".join([w[0] for w in str(self).split()])
return mark_safe("<span class='badge badge-{} badge-pill' data-toggle='tooltip' title='{}'>{}</span>".format(self.department_colour, str(self), icon))
@reversion.register
class TrainingLevelRequirement(models.Model, RevisionMixin):
@@ -238,11 +254,7 @@ class TrainingLevelQualification(models.Model, RevisionMixin):
@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))
return self.level.get_icon
def __str__(self):
if self.level.is_common_competencies:

View File

@@ -16,7 +16,7 @@
{% if item.active %}
<li class="list-group-item">{{ item }}</li>
{% elif request.user.is_superuser %}
<li class="list-group-item text-warning">{{ item }} (inactive)</li>
<li class="list-group-item text-warning">{{ item }}</li>
{% endif %}
{% endfor %}
</div>

View File

@@ -35,9 +35,9 @@
{% for object in object_list %}
<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>
<td {% if object.is_driver %}class="table-success"{%endif%}>{{ object.is_driver|yesno|title }}</td>
<td>{{ object.is_driver|yesno|title }}</td>
<td>{% for level in object|get_levels_of_depth:1 %}{% if forloop.first %}Yes {%endif%}{{ level.get_icon }}{%empty%}No{%endfor%}</td>
<td {% if object.is_supervisor %}class="table-success"{%endif%}>{% for level in object|get_levels_of_depth:2 %}{% if forloop.first %}Yes {%endif%}{{ level.get_icon }}{%empty%}No{%endfor%}</td>
<td>{% for level in object|get_levels_of_depth:2 %}{% if forloop.first %}Yes {%endif%}{{ level.get_icon }}{%empty%}No{%endfor%}</td>
<td>{{ object.num_qualifications }} {% if forloop.first %} <span class="fas fa-crown text-warning"></span>{% endif %}</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>

View File

@@ -11,10 +11,10 @@ register = template.Library()
@register.simple_tag
def user_has_qualification(user, item, depth):
if models.TrainingItem.user_has_qualification(item, user, depth) is not None:
return mark_safe("<span class='fas fa-check text-success'></span>")
if models.TrainingItem.user_has_qualification(item, user, depth):
return mark_safe("<span class='fas fa-check text-success' title='You have this requirement'></span>")
else:
return mark_safe("<span class='fas fa-hourglass-start text-warning'></span>")
return mark_safe("<span class='fas fa-hourglass-start text-warning' title='You do not yet have this requirement'></span>")
@register.simple_tag

View File

@@ -73,7 +73,7 @@ class LevelDetail(generic.DetailView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["page_title"] = "Training Level {} <span class='badge badge-{} badge-pill'><span class='fas fa-{}'></span></span>".format(self.object, self.object.department_colour, self.object.icon)
context["page_title"] = "Training Level {} {}".format(self.object, self.object.get_icon)
context["users_with"] = map(lambda qual: qual.trainee, models.TrainingLevelQualification.objects.filter(level=self.object))
return context