diff --git a/stages/admin.py b/stages/admin.py
index 7c20148..d6533f8 100644
--- a/stages/admin.py
+++ b/stages/admin.py
@@ -1,14 +1,14 @@
from django.contrib import admin
-from stages.models import (Student, Section, Referent, Corporation, CorpContact,
+from stages.models import (Student, Section, Klass, Referent, Corporation, CorpContact,
Domain, Period, Availability, Training)
class StudentAdmin(admin.ModelAdmin):
- list_display = ('__unicode__', 'pcode', 'city', 'section')
- list_filter = ('section',)
+ list_display = ('__unicode__', 'pcode', 'city', 'klass')
+ list_filter = ('klass',)
fields = (('last_name', 'first_name'), ('pcode', 'city'),
- 'birth_date', 'section')
+ 'birth_date', 'klass')
class CorpContactAdmin(admin.ModelAdmin):
@@ -41,8 +41,9 @@ class AvailabilityAdmin(admin.ModelAdmin):
fields = (('corporation', 'period'), 'domain', 'comment')
-admin.site.register(Student, StudentAdmin)
admin.site.register(Section)
+admin.site.register(Klass)
+admin.site.register(Student, StudentAdmin)
admin.site.register(Referent)
admin.site.register(Corporation, CorporationAdmin)
admin.site.register(CorpContact, CorpContactAdmin)
diff --git a/stages/fixtures/test_fixture.json b/stages/fixtures/test_fixture.json
index 0a1d01a..f481ded 100644
--- a/stages/fixtures/test_fixture.json
+++ b/stages/fixtures/test_fixture.json
@@ -20,6 +20,14 @@
"name": "EDE"
}
},
+ {
+ "pk": 1,
+ "model": "stages.klass",
+ "fields": {
+ "name": "1ASE3",
+ "section": 1
+ }
+ },
{
"pk": 1,
"model": "stages.student",
@@ -27,7 +35,7 @@
"city": "La Chaux-de-Fonds",
"first_name": "Albin",
"last_name": "Dupond",
- "section": 1,
+ "klass": 1,
"pcode": "2300",
"birth_date": "1994-05-12"
}
@@ -39,7 +47,7 @@
"city": "Neuch\u00e2tel",
"first_name": "Justine",
"last_name": "Varrin",
- "section": 1,
+ "klass": 1,
"pcode": "2000",
"birth_date": "1994-07-12"
}
@@ -51,7 +59,7 @@
"city": "Cernier",
"first_name": "Elvire",
"last_name": "Hickx",
- "section": 1,
+ "klass": 1,
"pcode": "2053",
"birth_date": "1994-05-20"
}
@@ -63,7 +71,7 @@
"city": "La Sagne",
"first_name": "Andr\u00e9",
"last_name": "Allemand",
- "section": 1,
+ "klass": 1,
"pcode": "2314",
"birth_date": "1994-10-11"
}
diff --git a/stages/models.py b/stages/models.py
index 7437bf1..cde563f 100644
--- a/stages/models.py
+++ b/stages/models.py
@@ -15,13 +15,24 @@ class Section(models.Model):
return self.name
+class Klass(models.Model):
+ name = models.CharField(max_length=10, verbose_name='Nom')
+ section = models.ForeignKey(Section)
+
+ class Meta:
+ verbose_name = "Classe"
+
+ def __unicode__(self):
+ return self.name
+
+
class Student(models.Model):
first_name = models.CharField(max_length=40, verbose_name='Prénom')
last_name = models.CharField(max_length=40, verbose_name='Nom')
birth_date = models.DateField(verbose_name='Date de naissance')
pcode = models.CharField(max_length=4, verbose_name='Code postal')
city = models.CharField(max_length=40, verbose_name='Localité')
- section = models.ForeignKey(Section)
+ klass = models.ForeignKey(Klass)
class Meta:
verbose_name = "Étudiant"
diff --git a/stages/views.py b/stages/views.py
index 2193459..c18f9cd 100644
--- a/stages/views.py
+++ b/stages/views.py
@@ -56,9 +56,13 @@ def period_students(request, pk):
if existing (JSON)
"""
period = get_object_or_404(Period, pk=pk)
- students = period.section.student_set.all().order_by('last_name')
+ students = Student.objects.filter(klass__section=period.section).order_by('last_name')
trainings = dict((t.student_id, t.id) for t in Training.objects.filter(availability__period=period))
- data = [{'name': unicode(s), 'id': s.id, 'training_id': trainings.get(s.id)} for s in students]
+ data = [{
+ 'name': unicode(s),
+ 'id': s.id,
+ 'training_id': trainings.get(s.id),
+ 'klass': s.klass.name} for s in students]
return HttpResponse(json.dumps(data), content_type="application/json")
def period_availabilities(request, pk):
@@ -90,7 +94,7 @@ def stages_export(request):
export_fields = [
('Prénom', 'student__first_name'), ('Nom', 'student__last_name'),
- ('Filière', 'student__section__name'),
+ ('Classe', 'student__klass__name'), ('Filière', 'student__klass__section__name'),
('Début', 'availability__period__start_date'), ('Fin', 'availability__period__end_date'),
('Institution', 'availability__corporation__name'),
('Domaine', 'availability__domain__name'),
diff --git a/templates/attribution.html b/templates/attribution.html
index 72cdee4..92ae812 100644
--- a/templates/attribution.html
+++ b/templates/attribution.html
@@ -52,7 +52,9 @@ function update_students(period_id) {
$.getJSON('/period/' + period_id + '/students/', function(data) {
var sel = $('#student_select');
$.each(data, function() {
- if (this.training_id == null) sel.append($("").val(this.id).text(this.name));
+ if (this.training_id == null) {
+ sel.append($("").val(this.id).text(this.name + ' (' + this.klass + ')').data('klass', this.klass));
+ }
})
});
}