Add klass level between student and section

This commit is contained in:
Claude Paroz 2012-11-08 18:27:04 +01:00
parent 06a271363d
commit 47aaba639b
5 changed files with 40 additions and 14 deletions

View file

@ -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)

View file

@ -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"
}

View file

@ -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"

View file

@ -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'),