mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Hotfix: Unable to add training item in requirements form
This commit is contained in:
@@ -15,6 +15,10 @@ def validate_user_can_train_in(supervisor, item):
|
||||
|
||||
|
||||
class QualificationForm(forms.ModelForm):
|
||||
related_models = {
|
||||
'item': models.TrainingItem
|
||||
}
|
||||
|
||||
class Meta:
|
||||
model = models.TrainingItemQualification
|
||||
fields = '__all__'
|
||||
@@ -49,6 +53,10 @@ class QualificationForm(forms.ModelForm):
|
||||
|
||||
|
||||
class RequirementForm(forms.ModelForm):
|
||||
related_models = {
|
||||
'item': models.TrainingItem
|
||||
}
|
||||
|
||||
depth = forms.ChoiceField(choices=models.TrainingItemQualification.CHOICES)
|
||||
|
||||
class Meta:
|
||||
|
||||
@@ -32,11 +32,7 @@
|
||||
{% endif %}
|
||||
<form id="requirement-form" action="{{ form.action|default:request.path }}" method="post">{% csrf_token %}
|
||||
{% render_field form.level|attr:'hidden' value=form.level.initial %}
|
||||
<div class="form-group form-row">
|
||||
<label for="item_id" class="col-sm-2 col-form-label">Item</label>
|
||||
<select name="item" id="item_id" class="form-control selectpicker custom-select col-sm-10" data-live-search="true" data-sourceurl="{% url 'api_secure' model='training_item' %}" required>
|
||||
</select>
|
||||
</div>
|
||||
{% include 'partials/item_field.html' %}
|
||||
<div class="form-group form-row">
|
||||
<label for="depth" class="col-sm-2 col-form-label">Depth</label>
|
||||
{% render_field form.depth|add_class:'form-control col-sm'|attr:'required' %}
|
||||
|
||||
@@ -28,14 +28,7 @@
|
||||
{% include 'form_errors.html' %}
|
||||
{% csrf_token %}
|
||||
{% render_field form.trainee|attr:'hidden' value=form.trainee.initial %}
|
||||
<div class="form-group form-row">
|
||||
<label for="item_id" class="col col-form-label">Item</label>
|
||||
<select name="item" id="item_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" required>
|
||||
{% if object.item %}
|
||||
<option value="{{object.item.pk}}" selected>{{object.item}}</option>
|
||||
{% endif %}
|
||||
</select>
|
||||
</div>
|
||||
{% include 'partials/item_field.html' %}
|
||||
<div class="form-group form-row">
|
||||
<label for="depth" class="col-sm-2 col-form-label">Depth</label>
|
||||
{% render_field form.depth|add_class:'form-control custom-select col-sm-8' %}
|
||||
|
||||
8
training/templates/partials/item_field.html
Normal file
8
training/templates/partials/item_field.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<div class="form-group form-row">
|
||||
<label for="item_id" class="col col-form-label">Item</label>
|
||||
<select name="item" id="item_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" required>
|
||||
{% if item %}
|
||||
<option value="{{form.item.pk}}" selected>{{item}}</option>
|
||||
{% endif %}
|
||||
</select>
|
||||
</div>
|
||||
@@ -118,6 +118,7 @@ class AddQualification(generic.CreateView, ModalURLMixin):
|
||||
context['override'] = 'base_training.html'
|
||||
trainee = models.Trainee.objects.get(pk=self.kwargs['pk'])
|
||||
context['page_title'] = f"Add Qualification for {trainee}"
|
||||
get_related(context['form'], context)
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
@@ -138,6 +139,7 @@ class EditQualification(generic.UpdateView):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["depths"] = models.TrainingItemQualification.CHOICES
|
||||
context['page_title'] = f"Edit Qualification <em>{self.object}</em> for {self.object.trainee}"
|
||||
get_related(context['form'], context)
|
||||
return context
|
||||
|
||||
@transaction.atomic()
|
||||
@@ -156,6 +158,7 @@ class AddLevelRequirement(generic.CreateView, ModalURLMixin):
|
||||
context = super().get_context_data(**kwargs)
|
||||
level = models.TrainingLevel.objects.get(pk=self.kwargs['pk'])
|
||||
context["page_title"] = f"Add Requirements to Training Level {level}"
|
||||
get_related(context['form'], context)
|
||||
return context
|
||||
|
||||
def get_form_kwargs(self):
|
||||
|
||||
Reference in New Issue
Block a user