Compare commits

...

4 Commits

Author SHA1 Message Date
046d0e461d Fix is_supervisor returning true if user has any levels
Whoops!
2022-01-02 11:15:03 +00:00
b73b8401b6 Add ordering to training level qualification 2022-01-02 11:06:58 +00:00
3fe388af26 Fix importer trying to set pk for qualifications
This doesn't work because of the old DB structure
2022-01-02 11:05:08 +00:00
22dc83d595 Do not display qualified levels also as started 2022-01-02 10:37:48 +00:00
7 changed files with 51 additions and 20 deletions

View File

@@ -124,8 +124,9 @@ class Command(BaseCommand):
for child in root:
depths = [("Training_Started", models.TrainingItemQualification.STARTED),
("Training_Complete", models.TrainingItemQualification.COMPLETE),
("Competency_Assessed", models.TrainingItemQualification.PASSED_OUT)]
for depth, depth_index in depths:
("Competency_Assessed", models.TrainingItemQualification.PASSED_OUT),]
for (depth, depth_index) in depths:
if child.find('{}_Date'.format(depth)) is not None:
if child.find('{}_Assessor_ID'.format(depth)) is None:
print("Training Record #{} had no supervisor. Assigning System User.".format(child.find('ID').text))
@@ -138,7 +139,6 @@ class Command(BaseCommand):
continue
try:
obj, created = models.TrainingItemQualification.objects.update_or_create(
pk=int(child.find('ID').text),
item=models.TrainingItem.objects.get(pk=int(child.find('Training_Item_ID').text)),
trainee=Profile.objects.get(pk=self.id_map[child.find('Member_ID').text]),
depth=depth_index,
@@ -154,7 +154,7 @@ class Command(BaseCommand):
else:
tally[0] += 1
except IntegrityError: # Eh?
print("Training Record #{} is duplicate. ಠ_ಠ".format(child.find('ID').text))
print("Training Record #{} is probably duplicate. ಠ_ಠ".format(child.find('ID').text))
except AttributeError:
print(child.find('ID').text)

View File

@@ -0,0 +1,23 @@
# Generated by Django 3.1.13 on 2022-01-02 11:06
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('training', '0010_auto_20211228_1144'),
]
operations = [
migrations.AlterModelOptions(
name='traininglevelqualification',
options={'ordering': ['-confirmed_on']},
),
migrations.AlterField(
model_name='traininglevelqualification',
name='trainee',
field=models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, related_name='level_qualifications', to='training.trainee'),
),
]

View File

@@ -12,15 +12,14 @@ class Trainee(Profile, RevisionMixin):
class Meta:
proxy = True
# TODO remove levels that the user has a qualification in
# FIXME use queryset
def started_levels(self):
return [level for level in TrainingLevel.objects.all() if level.percentage_complete(self) > 0]
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_supervisor(self):
return self.level_qualifications.all().exclude(confirmed_on=None).select_related('level') \
.filter(level__gte=TrainingLevel.SUPERVISOR) \
.filter(level__level__gte=TrainingLevel.SUPERVISOR) \
.exclude(level__department=TrainingLevel.HAULAGE) \
.exclude(level__department__isnull=True).exists()
@@ -109,6 +108,9 @@ class TrainingItemQualification(models.Model):
else:
return "info"
def get_absolute_url(self):
return reverse('trainee_item_detail', kwargs={'pk': self.trainee.pk})
class Meta:
unique_together = ["trainee", "item", "depth"]
order_with_respect_to = 'item'
@@ -249,3 +251,4 @@ class TrainingLevelQualification(models.Model, RevisionMixin):
class Meta:
unique_together = ["trainee", "level"]
ordering = ['-confirmed_on']

View File

@@ -96,6 +96,9 @@
<div class="card mb-3 d-none d-md-block">
<h4 class="card-header">Users with this level</h4>
<div class="card-body">
{% for user in users_with %}
{% user_level_if_present user object as level_qualification %}
{% if forloop.first %}
<table class="table table-sm">
<thead>
<tr>
@@ -105,18 +108,19 @@
</tr>
</thead>
<tbody>
{% for user in users_with %}
{% user_level_if_present user object as level_qualification %}
<tr {% if not level_qualification.confirmed_on %}style="border-style: dashed; opacity: 80%"{%endif%}>
<td><img src="{{user.profile_picture}}" style="width: 50px" class="img-thumbnail"/> {{user}}</td>
<td>{% if level_qualification.confirmed_on %}<p class="card-text"><small>Qualified on {{ level_qualification.confirmed_on }}</small></p>{%else%}Unconfirmed{%endif%}</td>
<td><a href="{% url 'profile_detail' user.pk %}" class="btn btn-primary btn-sm"><span class="fas fa-user"></span> View Profile</a></div></td>
</tr>
{% empty %}
Nobody here but us chickens... <span class="fas fa-egg text-warning"></span>
{% endfor %}
{% endif %}
<tr {% if not level_qualification.confirmed_on %}style="border-style: dashed; opacity: 80%"{%endif%}>
<td><img src="{{user.profile_picture}}" style="width: 50px" class="img-thumbnail"/> {{user}}</td>
<td>{% if level_qualification.confirmed_on %}<p class="card-text"><small>Qualified on {{ level_qualification.confirmed_on }}</small></p>{%else%}Unconfirmed{%endif%}</td>
<td><a href="{% url 'profile_detail' user.pk %}" class="btn btn-primary btn-sm"><span class="fas fa-user"></span> View Profile</a></div></td>
</tr>
{% if forloop.last %}
</tbody>
</table>
{% endif %}
{% empty %}
Nobody here but us chickens... <span class="fas fa-egg text-warning"></span>
{% endfor %}
</div>
</div>
<div class="row">

View File

@@ -38,7 +38,7 @@
<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 %}{% 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>{{ object.num_qualifications }}</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>
<a href="{% url 'trainee_item_detail' pk=object.pk %}" class="btn btn-info"><span class="fas fa-info-circle"></span> View Detailed Record</a>

View File

@@ -39,4 +39,4 @@ def get_supervisor(tech):
@register.filter
def get_levels_of_depth(trainee, level):
return trainee.level_qualifications.all().exclude(confirmed_on=None).select_related('level').filter(level__level=level)
return trainee.level_qualifications.all().exclude(confirmed_on=None).exclude(level__department=models.TrainingLevel.HAULAGE).select_related('level').filter(level__level=level)

View File

@@ -51,7 +51,8 @@ class TraineeItemDetail(generic.ListView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["page_title"] = "Detailed Training Record for {}".format(models.Trainee.objects.get(pk=self.kwargs['pk']))
trainee = models.Trainee.objects.get(pk=self.kwargs['pk'])
context["page_title"] = "Detailed Training Record for <a href='{}'>{}</a>".format(trainee.get_absolute_url(), trainee)
return context