mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-29 19:32:14 +00:00
FEAT(T): Add ability to log items at various depths during a session
Also fixes inability to search by reference number
This commit is contained in:
@@ -71,8 +71,9 @@ class RequirementForm(forms.ModelForm):
|
|||||||
|
|
||||||
class SessionLogForm(forms.Form):
|
class SessionLogForm(forms.Form):
|
||||||
trainees = forms.ModelMultipleChoiceField(models.Trainee.objects.all())
|
trainees = forms.ModelMultipleChoiceField(models.Trainee.objects.all())
|
||||||
items = forms.ModelMultipleChoiceField(models.TrainingItem.objects.all())
|
items_0 = forms.ModelMultipleChoiceField(models.TrainingItem.objects.all(), required=False)
|
||||||
depth = forms.ChoiceField(choices=models.TrainingItemQualification.CHOICES)
|
items_1 = forms.ModelMultipleChoiceField(models.TrainingItem.objects.all(), required=False)
|
||||||
|
items_2 = forms.ModelMultipleChoiceField(models.TrainingItem.objects.all(), required=False)
|
||||||
supervisor = forms.ModelChoiceField(models.Trainee.objects.all())
|
supervisor = forms.ModelChoiceField(models.Trainee.objects.all())
|
||||||
date = forms.DateField(initial=datetime.date.today)
|
date = forms.DateField(initial=datetime.date.today)
|
||||||
notes = forms.CharField(required=False, widget=forms.Textarea)
|
notes = forms.CharField(required=False, widget=forms.Textarea)
|
||||||
@@ -88,6 +89,7 @@ class SessionLogForm(forms.Form):
|
|||||||
supervisor = self.cleaned_data['supervisor']
|
supervisor = self.cleaned_data['supervisor']
|
||||||
if supervisor in self.cleaned_data.get('trainees', []):
|
if supervisor in self.cleaned_data.get('trainees', []):
|
||||||
raise forms.ValidationError('One may not supervise oneself...')
|
raise forms.ValidationError('One may not supervise oneself...')
|
||||||
for item in self.cleaned_data.get('items', []):
|
for depth in models.TrainingItemQualification.CHOICES:
|
||||||
validate_user_can_train_in(supervisor, item)
|
for item in self.cleaned_data.get('items_{depth.0}', []):
|
||||||
|
validate_user_can_train_in(supervisor, item)
|
||||||
return supervisor
|
return supervisor
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
{% load static %}
|
{% load static %}
|
||||||
{% load button from filters %}
|
{% load button from filters %}
|
||||||
|
{% load colour_from_depth from tags %}
|
||||||
|
|
||||||
{% block css %}
|
{% block css %}
|
||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
@@ -36,18 +37,16 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<h3>Training Items</h3>
|
<h3>Training Items</h3>
|
||||||
<div class="row px-3">
|
{% for depth in depths %}
|
||||||
<div class="form-group">
|
<div class="form-group row">
|
||||||
<label for="selectpicker">Training Items</label>
|
<label for="selectpicker" class="col-sm-2 rounded bg-{% colour_from_depth depth.0 %} text-center py-1">{{ depth.1 }} Items</label>
|
||||||
<select multiple name="items" id="items_id" class="selectpicker col-12 px-0" data-live-search="true" data-sourceurl="{% url 'api_secure' model='training_item' %}?fields=description,reference_number&filters=active">
|
<select multiple name="items_{{depth.0}}" id="items_{{depth.0}}_id" class="selectpicker col-sm-10 px-0" data-live-search="true" data-sourceurl="{% url 'api_secure' model='training_item' %}?fields=display_id,description&filters=active">
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group pl-3">
|
{% endfor %}
|
||||||
{% include 'partials/form_field.html' with field=form.depth %}
|
<h3>Session Information</h3>
|
||||||
</div>
|
<div class="form-group">
|
||||||
<div class="form-group pl-3">
|
{% include 'partials/form_field.html' with field=form.date %}
|
||||||
{% include 'partials/form_field.html' with field=form.date %}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
{% include 'partials/form_field.html' with field=form.notes %}
|
{% include 'partials/form_field.html' with field=form.notes %}
|
||||||
|
|||||||
@@ -219,18 +219,20 @@ class SessionLog(generic.FormView):
|
|||||||
success_url = reverse_lazy('trainee_list')
|
success_url = reverse_lazy('trainee_list')
|
||||||
|
|
||||||
def form_valid(self, form, *args, **kwargs):
|
def form_valid(self, form, *args, **kwargs):
|
||||||
for trainee in form.cleaned_data.get('trainees'):
|
for trainee in form.cleaned_data.get('trainees', []):
|
||||||
for item in form.cleaned_data.get('items'):
|
for depth in models.TrainingItemQualification.CHOICES:
|
||||||
try:
|
for item in form.cleaned_data.get(f'items_{depth[0]}', []):
|
||||||
with transaction.atomic():
|
try:
|
||||||
models.TrainingItemQualification.objects.create(trainee=trainee, item=item, supervisor=form.cleaned_data.get('supervisor'), depth=form.cleaned_data.get('depth'), notes=form.cleaned_data.get('notes'), date=form.cleaned_data.get('date'))
|
with transaction.atomic():
|
||||||
reversion.add_to_revision(trainee)
|
models.TrainingItemQualification.objects.create(trainee=trainee, item=item, supervisor=form.cleaned_data.get('supervisor'), depth=depth[0], notes=form.cleaned_data.get('notes'), date=form.cleaned_data.get('date'))
|
||||||
except IntegrityError:
|
reversion.add_to_revision(trainee)
|
||||||
pass # There was an attempt to create a duplicate qualification, ignore it
|
except IntegrityError:
|
||||||
|
pass # There was an attempt to create a duplicate qualification, ignore it
|
||||||
return super().form_valid(form, *args, **kwargs)
|
return super().form_valid(form, *args, **kwargs)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
context["depths"] = models.TrainingItemQualification.CHOICES
|
||||||
context["page_title"] = "Log Training Session"
|
context["page_title"] = "Log Training Session"
|
||||||
get_related(context['form'], context)
|
get_related(context['form'], context)
|
||||||
return context
|
return context
|
||||||
|
|||||||
Reference in New Issue
Block a user