From e0b60bd37173a9129766a227ee27d2b479d48336 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Tue, 13 Nov 2012 14:08:34 +0100 Subject: [PATCH] Add class filter in attribution interface --- common/urls.py | 1 + stages/views.py | 6 +++++ templates/attribution.html | 45 +++++++++++++++++++++++++++++++++----- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/common/urls.py b/common/urls.py index b8ff1e3..10c8505 100644 --- a/common/urls.py +++ b/common/urls.py @@ -21,6 +21,7 @@ urlpatterns = patterns('', # AJAX/JSON urls url(r'^section/(?P\d+)/periods/', 'stages.views.section_periods'), + url(r'^section/(?P\d+)/classes/', 'stages.views.section_classes'), url(r'^period/(?P\d+)/students/', 'stages.views.period_students'), url(r'^period/(?P\d+)/corporations/', 'stages.views.period_availabilities'), # Training params in POST: diff --git a/stages/views.py b/stages/views.py index e42c687..263a1c3 100644 --- a/stages/views.py +++ b/stages/views.py @@ -51,6 +51,12 @@ def section_periods(request, pk): periods = [(p.id, p.dates) for p in section.period_set.all()] return HttpResponse(json.dumps(periods), content_type="application/json") +def section_classes(request, pk): + section = get_object_or_404(Section, pk=pk) + classes = [(k.id, k.name) for k in section.klass_set.all()] + return HttpResponse(json.dumps(classes), content_type="application/json") + + def period_students(request, pk): """ Return all students from period's section, with corresponding Training if existing (JSON) diff --git a/templates/attribution.html b/templates/attribution.html index ebf673e..fb33dc8 100644 --- a/templates/attribution.html +++ b/templates/attribution.html @@ -9,7 +9,7 @@ select#period_select { width: 16em; } div#student_choice { float: left; width: 18%; } - select#student_select { width: 100%; } + select#student_select, select#student_filter { width: 100%; } div#corp_choice { float: right; width: 18%; } select#corp_select { width: 100%; } @@ -45,24 +45,41 @@ function update_periods(section_id) { }); } +function update_class_filter(section_id) { + $('#student_filter').empty(); + $.getJSON('/section/' + section_id + '/classes/', function(data) { + var sel = $('#student_filter'); + sel.append($("