Implement stage deletion from attribution interface
This commit is contained in:
parent
e0b60bd371
commit
6abfe6487a
4 changed files with 30 additions and 9 deletions
|
|
@ -26,6 +26,7 @@ urlpatterns = patterns('',
|
|||
url(r'^period/(?P<pk>\d+)/corporations/', 'stages.views.period_availabilities'),
|
||||
# Training params in POST:
|
||||
url(r'^training/new/', 'stages.views.new_training', name="new_training"),
|
||||
url(r'^training/del/', 'stages.views.del_training', name="del_training"),
|
||||
url(r'^training/by_period/(?P<pk>\d+)/', views.TrainingsByPeriodView.as_view()),
|
||||
|
||||
url(r'^student/(?P<pk>\d+)/summary/', views.StudentSummaryView.as_view()),
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import json
|
|||
|
||||
from django.http import HttpResponse, HttpResponseNotAllowed
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.generic import DetailView, TemplateView, ListView
|
||||
|
||||
from .forms import PeriodForm
|
||||
|
|
@ -27,7 +26,7 @@ class TrainingsByPeriodView(ListView):
|
|||
context_object_name = 'trainings'
|
||||
|
||||
def get_queryset(self):
|
||||
return Training.objects.select_related('student', 'availability__corporation', 'availability__domain'
|
||||
return Training.objects.select_related('student__klass', 'availability__corporation', 'availability__domain'
|
||||
).filter(availability__period__pk=self.kwargs['pk'])
|
||||
|
||||
|
||||
|
|
@ -78,7 +77,6 @@ def period_availabilities(request, pk):
|
|||
for av in period.availability_set.select_related('corporation').all()]
|
||||
return HttpResponse(json.dumps(corps), content_type="application/json")
|
||||
|
||||
@csrf_exempt
|
||||
def new_training(request):
|
||||
if request.method != 'POST':
|
||||
return HttpResponseNotAllowed()
|
||||
|
|
@ -94,6 +92,13 @@ def new_training(request):
|
|||
return HttpResponse(str(exc))
|
||||
return HttpResponse('OK')
|
||||
|
||||
def del_training(request):
|
||||
if request.method != 'POST':
|
||||
return HttpResponseNotAllowed()
|
||||
training = get_object_or_404(Training, pk=request.POST.get('pk'))
|
||||
training.delete()
|
||||
return HttpResponse('OK')
|
||||
|
||||
|
||||
def stages_export(request):
|
||||
from datetime import date
|
||||
|
|
|
|||
|
|
@ -94,7 +94,20 @@ function update_corporations(period_id) {
|
|||
|
||||
function update_trainings(period_id) {
|
||||
if (period_id == '') $('ul#training_list').html('');
|
||||
else $('ul#training_list').load('/training/by_period/' + period_id + '/');
|
||||
else $('ul#training_list').load('/training/by_period/' + period_id + '/', function() {
|
||||
$('img.delete_training').click(function() {
|
||||
if (!confirm("Voulez-vous vraiment supprimer ce stage ?")) return;
|
||||
var li = $(this).parents('li');
|
||||
$.post('/training/del/',
|
||||
{pk: li.attr('id').split('_')[1],
|
||||
csrfmiddlewaretoken: $("input[name='csrfmiddlewaretoken']").val()}, function() {
|
||||
li.remove();
|
||||
// dispatch student and corp in their listings
|
||||
update_students($('#period_select').val());
|
||||
update_corporations($('#period_select').val());
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
|
|
@ -140,15 +153,15 @@ $(document).ready(function() {
|
|||
$('#valid_training').click(function() {
|
||||
$.post('/training/new/', {
|
||||
student: current_student, avail: current_avail,
|
||||
referent: $('#referent_select').val()},
|
||||
referent: $('#referent_select').val(),
|
||||
csrfmiddlewaretoken: $("input[name='csrfmiddlewaretoken']").val()},
|
||||
function(data) {
|
||||
if (data != 'OK') {
|
||||
alert(data);
|
||||
return;
|
||||
}
|
||||
// Clear selected student/corp
|
||||
$('ul#training_list').append('<li>' + $('option:selected', '#student_select').html() + ' - ' + $('option:selected', '#corp_select').html() + '</li>');
|
||||
$('option:selected', '#student_select').remove();
|
||||
$('option:selected', '#student_select').remove();
|
||||
$('#student_detail').html('').removeClass("filled");
|
||||
$('option:selected', '#corp_select').remove();
|
||||
$('#corp_detail').html('').removeClass("filled");
|
||||
|
|
@ -156,6 +169,7 @@ $(document).ready(function() {
|
|||
current_avail = null;
|
||||
$('input#valid_training').hide();
|
||||
$('#referent_select').val('');
|
||||
update_trainings($('#period_select').val());
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
@ -206,7 +220,7 @@ var current_avail = null;
|
|||
<div id="corp_detail"></div>
|
||||
</div>
|
||||
<div id="training_form">
|
||||
<form>
|
||||
<form>{% csrf_token %}
|
||||
<div id="referent_choice"><label for="referent_select">Référent:</label>
|
||||
<select id="referent_select"><option value="">-------</option>
|
||||
{% for ref in referents %}<option value="{{ ref.id }}">{{ ref }}</option>{% endfor %}</select>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{% for obj in trainings %}
|
||||
<li>{{ obj.student }} - {{ obj.availability.corporation }} - {{ obj.availability.domain }}
|
||||
<li id="training_{{ obj.id }}">{{ obj.student }} ({{ obj.student.klass }}) - {{ obj.availability.corporation }} - {{ obj.availability.domain }}
|
||||
{% if obj.referent %} (réf: {{ obj.referent }}){% else %}- <span class="missing">Pas de référent</span>{% endif %}
|
||||
<img class="delete_training" src="{{ STATIC_URL}}admin/img/icon_deletelink.gif">
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue