mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-10-10 14:52:53 +00:00
Add dropdown showing which training items technicians can deliver training in
This commit is contained in:
@@ -54,6 +54,26 @@
|
|||||||
{% button 'submit' %}
|
{% button 'submit' %}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
{% if request.user.can_log_training and not request.user.is_supervisor %}
|
||||||
|
<div class="mb-3">
|
||||||
|
<button class="btn btn-outline-secondary" type="button" data-bs-toggle="collapse" data-bs-target="#deliverable_items" aria-expanded="false" aria-controls="deliverable_items">
|
||||||
|
<span class="fas fa-question-circle"></span> What training items can I deliver training in?
|
||||||
|
</button>
|
||||||
|
<div class="collapse mt-3" id="deliverable_items">
|
||||||
|
<div class="card card-body">
|
||||||
|
<p class="text-muted">You may deliver up to Training Complete in these items, as you are a technician who is passed out in them. Passing people out is for supervisors only.</p>
|
||||||
|
{% for category, items in deliverable_items %}
|
||||||
|
<h5>{{ category }}</h5>
|
||||||
|
<ul>
|
||||||
|
{% for item in items %}<li>{{ item.display_name }}</li>{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% empty %}
|
||||||
|
<p class="mb-0">You can't currently deliver training in any items. An item must be marked as technician-trainable, you must be passed out in it, and you must hold any technician level its category requires.</p>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -192,6 +192,12 @@ def test_technician_session_log(client, trainee, supervisor, admin_user):
|
|||||||
assert models.TrainingItemQualification.objects.filter(
|
assert models.TrainingItemQualification.objects.filter(
|
||||||
trainee=admin_user.pk, item=item, depth=models.TrainingItemQualification.COMPLETE
|
trainee=admin_user.pk, item=item, depth=models.TrainingItemQualification.COMPLETE
|
||||||
).exists()
|
).exists()
|
||||||
|
# The list of deliverable items is shown, and only contains permitted items
|
||||||
|
response = client.get(url)
|
||||||
|
assertContains(response, "What training items can I deliver training in?")
|
||||||
|
assert [(c.pk, [i.pk for i in items]) for c, items in response.context["deliverable_items"]] == [
|
||||||
|
(item.category.pk, [item.pk])
|
||||||
|
]
|
||||||
# Passing out is not allowed
|
# Passing out is not allowed
|
||||||
response = client.post(url, {**data, "items_1": [], "items_2": [item.pk]})
|
response = client.post(url, {**data, "items_1": [], "items_2": [item.pk]})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
@@ -204,3 +210,8 @@ def test_technician_session_log(client, trainee, supervisor, admin_user):
|
|||||||
def test_plain_trainee_cannot_log_session(client, trainee):
|
def test_plain_trainee_cannot_log_session(client, trainee):
|
||||||
client.force_login(trainee)
|
client.force_login(trainee)
|
||||||
assert client.get(reverse("session_log")).status_code == 403
|
assert client.get(reverse("session_log")).status_code == 403
|
||||||
|
|
||||||
|
|
||||||
|
def test_supervisor_does_not_see_deliverable_items(admin_client):
|
||||||
|
response = admin_client.get(reverse("session_log"))
|
||||||
|
assertNotContains(response, "What training items can I deliver training in?")
|
||||||
|
|||||||
@@ -291,10 +291,25 @@ class SessionLog(generic.FormView):
|
|||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context["depths"] = models.TrainingItemQualification.CHOICES
|
context["depths"] = models.TrainingItemQualification.CHOICES
|
||||||
context["page_title"] = "Log Training Session"
|
context["page_title"] = "Log Training Session"
|
||||||
|
if not self.request.user.is_supervisor:
|
||||||
|
context["deliverable_items"] = self.get_deliverable_items()
|
||||||
get_related(context["form"], context)
|
get_related(context["form"], context)
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
def get_deliverable_items(self):
|
||||||
|
"""Active items the current user may deliver training in, grouped by category, using the same test as form validation"""
|
||||||
|
trainee = models.Trainee.objects.get(pk=self.request.user.pk)
|
||||||
|
items = models.TrainingItem.objects.filter(active=True, technician_can_train=True).select_related(
|
||||||
|
"category", "category__training_level"
|
||||||
|
)
|
||||||
|
grouped = {}
|
||||||
|
for item in items:
|
||||||
|
if trainee.can_deliver_training(item, models.TrainingItemQualification.COMPLETE):
|
||||||
|
grouped.setdefault(item.category, []).append(item)
|
||||||
|
return list(grouped.items())
|
||||||
|
|
||||||
|
|
||||||
class ItemQualifications(generic.ListView):
|
class ItemQualifications(generic.ListView):
|
||||||
template_name = "item_qualification_list.html"
|
template_name = "item_qualification_list.html"
|
||||||
model = models.TrainingItemQualification
|
model = models.TrainingItemQualification
|
||||||
|
|||||||
Reference in New Issue
Block a user