mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-18 14:02:15 +00:00
Add ability to edit past training records
This commit is contained in:
@@ -19,7 +19,7 @@ class QualificationForm(forms.ModelForm):
|
||||
pk = kwargs.pop('pk', None)
|
||||
super(QualificationForm, self).__init__(*args, **kwargs)
|
||||
self.fields['trainee'].initial = Profile.objects.get(pk=pk)
|
||||
self.fields['date'].initial = date.today()
|
||||
self.fields['date'].widget.format = '%Y-%m-%d'
|
||||
|
||||
def clean_date(self):
|
||||
date = self.cleaned_data['date']
|
||||
|
||||
@@ -93,7 +93,7 @@ class TrainingItemQualification(models.Model):
|
||||
# TODO Maximum depth - some things stop at Complete and you can't be passed out in them
|
||||
|
||||
def __str__(self):
|
||||
return "{} in {} on {}".format(self.depth, self.item, self.date)
|
||||
return "{} in {} on {}".format(self.get_depth_display(), self.item, self.date.strftime("%b %d %Y"))
|
||||
|
||||
@property
|
||||
def activity_feed_string(self):
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
<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-4" data-live-search="true" data-sourceurl="{% url 'api_secure' model='training_item' %}?fields=reference_number,name&filters=active" required>
|
||||
{% if object.item %}
|
||||
<option value="{{object.item.pk}}" selected>{{object.item}}</option>
|
||||
{% endif %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group form-row">
|
||||
@@ -40,20 +43,24 @@
|
||||
<div class="form-group form-row">
|
||||
<label for="supervisor" class="col-sm-2 col-form-label">Supervisor</label>
|
||||
<select name="supervisor" id="supervisor_id" class="form-control selectpicker custom-select col-sm-10" data-live-search="true" data-sourceurl="{% url 'api_secure' model='profile' %}?fields=first_name,last_name,initials" required>
|
||||
{% if object.supervisor %}
|
||||
<option value="{{object.supervisor.pk}}" selected>{{object.supervisor}}</option>
|
||||
{% endif %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group form-row">
|
||||
<label for="date" class="col-sm-2 col-form-label">Training Date</label>
|
||||
<div class="col-sm-8">
|
||||
{% render_field form.date|add_class:'form-control'|attr:'type="date"' value=form.date.initial %}
|
||||
{% with training_date=object.date|date:"Y-m-d" %}
|
||||
{% render_field form.date|add_class:'form-control'|attr:'type="date"' value=training_date %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
<button class="btn btn-info col-sm-2" onclick="var date = new Date(); $('#id_date').val([date.getFullYear(), ('0' + (date.getMonth()+1)).slice(-2), ('0' + date.getDate()).slice(-2)].join('-'))" tabindex="-1" type="button">Today</button>
|
||||
</div>
|
||||
<div class="form-group form-row">
|
||||
<label for="item_description" class="col-sm-2 col-form-label">Notes</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea type="text" placeholder="Notes" class="form-control"
|
||||
id="notes" rows="3"></textarea>
|
||||
<label for="id_notes" class="col-sm-2 col-form-label">Notes</label>
|
||||
<div class="col-sm-8">
|
||||
{% render_field form.notes|add_class:'form-control' rows=3 %}
|
||||
</div>
|
||||
</div>
|
||||
{% if not request.is_ajax %}
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
<th>Date</th>
|
||||
<th>Supervisor</th>
|
||||
<th>Notes</th>
|
||||
{% if request.user.is_supervisor or perms.training.change_trainingitemqualification %}
|
||||
<th></th>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -29,6 +32,9 @@
|
||||
<td>{{ object.date }}</td>
|
||||
<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>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr class="table-warning">
|
||||
|
||||
@@ -15,6 +15,8 @@ urlpatterns = [
|
||||
path('trainee/<int:pk>/history', permission_required_with_403('RIGS.view_profile')(VersionHistory.as_view()), name='trainee_history', kwargs={'model': models.Trainee, 'app': 'training'}), # Not picked up automatically because proxy model (I think)
|
||||
path('trainee/<int:pk>/add_qualification/', login_required(views.AddQualification.as_view()),
|
||||
name='add_qualification'),
|
||||
path('trainee/<int:pk>/edit_qualification/', permission_required_with_403('training.change_trainingitemqualification')(views.EditQualification.as_view()),
|
||||
name='edit_qualification'),
|
||||
path('session/', login_required(views.SessionLog.as_view()), name='session_log'),
|
||||
path('levels/', login_required(views.LevelList.as_view()), name='level_list'),
|
||||
path('level/<int:pk>/', login_required(views.LevelDetail.as_view()), name='level_detail'),
|
||||
|
||||
@@ -152,6 +152,23 @@ class AddQualification(generic.CreateView, ModalURLMixin):
|
||||
return kwargs
|
||||
|
||||
|
||||
class EditQualification(generic.UpdateView):
|
||||
template_name = 'edit_training_record.html'
|
||||
model = models.TrainingItemQualification
|
||||
form_class = forms.QualificationForm
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(EditQualification, self).get_context_data(**kwargs)
|
||||
context["depths"] = models.TrainingItemQualification.CHOICES
|
||||
context['page_title'] = "Edit Qualification {} for {}".format(self.object, models.Trainee.objects.get(pk=self.kwargs['pk']))
|
||||
return context
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(EditQualification, self).get_form_kwargs()
|
||||
kwargs['pk'] = self.kwargs['pk']
|
||||
return kwargs
|
||||
|
||||
|
||||
class AddLevelRequirement(generic.CreateView, ModalURLMixin):
|
||||
template_name = "add_level_requirement.html"
|
||||
model = models.TrainingLevelRequirement
|
||||
|
||||
Reference in New Issue
Block a user