mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Modalise training item qualification edit
Also fixed some stuff
This commit is contained in:
@@ -3,15 +3,14 @@ import datetime
|
||||
from django import forms
|
||||
|
||||
from training import models
|
||||
from RIGS.models import Profile
|
||||
|
||||
|
||||
def validate_user_can_train_in(supervisor, item):
|
||||
def validate_user_can_train_in(self, supervisor, item):
|
||||
if item.category.training_level:
|
||||
if not supervisor.level_qualifications.filter(level=item.category.training_level):
|
||||
raise forms.ValidationError('Selected supervising person is missing requisite training level to train in this department')
|
||||
self.add_error('supervisor', 'Selected supervising person is missing requisite training level to train in this department')
|
||||
elif not supervisor.is_supervisor:
|
||||
raise forms.ValidationError('Selected supervisor must actually *be* a supervisor...')
|
||||
self.add_error('supervisor', 'Selected supervisor must actually *be* a supervisor...')
|
||||
|
||||
|
||||
class QualificationForm(forms.ModelForm):
|
||||
@@ -28,8 +27,9 @@ class QualificationForm(forms.ModelForm):
|
||||
cleaned_data = super().clean()
|
||||
item = cleaned_data.get('item')
|
||||
trainee = cleaned_data.get('trainee')
|
||||
supervisor = self.cleaned_data.get('supervisor')
|
||||
validate_user_can_train_in(supervisor, item)
|
||||
supervisor = cleaned_data.get('supervisor')
|
||||
if supervisor:
|
||||
validate_user_can_train_in(self, supervisor, item)
|
||||
if not item.user_has_requirements(trainee):
|
||||
self.add_error('item', 'Missing prerequisites')
|
||||
|
||||
@@ -52,10 +52,10 @@ class QualificationForm(forms.ModelForm):
|
||||
|
||||
class AddQualificationForm(QualificationForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs.pop('pk', None)
|
||||
pk = kwargs.pop('pk', None)
|
||||
super().__init__(*args, **kwargs)
|
||||
if pk:
|
||||
self.fields['trainee'].initial = Profile.objects.get(pk=pk)
|
||||
self.fields['trainee'].initial = models.Trainee.objects.get(pk=pk)
|
||||
|
||||
|
||||
class RequirementForm(forms.ModelForm):
|
||||
@@ -97,5 +97,5 @@ class SessionLogForm(forms.Form):
|
||||
raise forms.ValidationError('One may not supervise oneself...')
|
||||
for depth in models.TrainingItemQualification.CHOICES:
|
||||
for item in self.cleaned_data.get('items_{depth.0}', []):
|
||||
validate_user_can_train_in(supervisor, item)
|
||||
validate_user_can_train_in(self, supervisor, item)
|
||||
return supervisor
|
||||
|
||||
@@ -198,7 +198,7 @@ class TrainingItemQualification(models.Model, RevisionMixin):
|
||||
return "info"
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('trainee_item_detail', kwargs={'pk': self.trainee.pk})
|
||||
return reverse('edit_qualification', kwargs={'pk': self.pk})
|
||||
|
||||
class Meta:
|
||||
unique_together = ["trainee", "item", "depth"]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<label for="supervisor" class="col-sm-2 col-form-label">Supervisor</label>
|
||||
<select name="supervisor" id="supervisor_id" class="selectpicker col-sm-10" data-live-search="true" data-sourceurl="{% url 'api_secure' model='profile' %}?fields=first_name,last_name,initials" required>
|
||||
{% if supervisor %}
|
||||
<option value="{{form.supervisor.value}}" selected="selected">{{ supervisor }}</option>
|
||||
<option value="{{form.supervisor.value}}" selected>{{ supervisor }}</option>
|
||||
{% endif %}
|
||||
</select>
|
||||
|
||||
@@ -5,6 +5,41 @@
|
||||
{% load linkornone from filters %}
|
||||
{% load button from filters %}
|
||||
{% load colour_from_depth from tags %}
|
||||
{% load static %}
|
||||
|
||||
{% block css %}
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'css/selects.css' %}"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block preload_js %}
|
||||
<script src="{% static 'js/selects.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script src="{% static 'js/tooltip.js' %}"></script>
|
||||
<script>
|
||||
$('document').ready(function(){
|
||||
$('#edit').click(function (e) {
|
||||
e.preventDefault();
|
||||
var url = $(this).attr("href");
|
||||
$.ajax({
|
||||
url: url,
|
||||
success: function(){
|
||||
$link = $(this);
|
||||
// Anti modal inception
|
||||
if ($link.parents('#modal').length === 0) {
|
||||
modaltarget = $link.data('target');
|
||||
modalobject = "";
|
||||
$('#modal').load(url, function (e) {
|
||||
$('#modal').modal();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p class="text-muted text-right">Search by supervisor name, item name or item ID</p>{% include 'partials/list_search.html' %}
|
||||
@@ -33,7 +68,7 @@
|
||||
<td><a href="{{ object.supervisor.get_absolute_url}}">{{ object.supervisor }}</a></td>
|
||||
<td>{{ object.notes }}</td>
|
||||
{% if request.user.is_supervisor or perms.training.change_trainingitemqualification %}
|
||||
<td>{% button 'edit' 'edit_qualification' object.pk %}</td>
|
||||
<td>{% button 'edit' 'edit_qualification' object.pk id="edit" %}</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% empty %}
|
||||
|
||||
@@ -17,6 +17,7 @@ def test_add_qualification(admin_client, trainee, admin_user, training_item):
|
||||
assertFormError(response, 'form', 'date', 'Qualification date may not be in the future')
|
||||
assertFormError(response, 'form', 'supervisor', 'One may not supervise oneself...')
|
||||
response = admin_client.post(url, {'date': date, 'trainee': trainee.pk, 'supervisor': admin_user.pk, 'item': training_item.pk})
|
||||
print(response.content)
|
||||
assertFormError(response, 'form', 'supervisor', 'Selected supervisor must actually *be* a supervisor...')
|
||||
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ class AddQualification(generic.CreateView, ModalURLMixin):
|
||||
return kwargs
|
||||
|
||||
|
||||
class EditQualification(generic.UpdateView):
|
||||
class EditQualification(generic.UpdateView, ModalURLMixin):
|
||||
template_name = 'edit_training_record.html'
|
||||
model = models.TrainingItemQualification
|
||||
form_class = forms.QualificationForm
|
||||
@@ -148,6 +148,9 @@ class EditQualification(generic.UpdateView):
|
||||
reversion.add_to_revision(form.cleaned_data['trainee'])
|
||||
return super().form_valid(form, *args, **kwargs)
|
||||
|
||||
def get_success_url(self):
|
||||
return self.get_close_url('edit_qualification', 'trainee_item_detail')
|
||||
|
||||
|
||||
class AddLevelRequirement(generic.CreateView, ModalURLMixin):
|
||||
template_name = "add_level_requirement.html"
|
||||
|
||||
Reference in New Issue
Block a user