Use candidate information in student import
This commit is contained in:
parent
3c3ae13ac2
commit
c0074d186d
2 changed files with 64 additions and 9 deletions
|
|
@ -9,6 +9,7 @@ from django.test import TestCase, override_settings
|
|||
from django.urls import reverse
|
||||
from django.utils.html import escape
|
||||
|
||||
from candidats.models import Candidate
|
||||
from .models import (
|
||||
Level, Domain, Section, Klass, Option, Period, Student, Corporation, Availability,
|
||||
CorpContact, Teacher, Training, Course,
|
||||
|
|
@ -439,12 +440,36 @@ class ImportTests(TestCase):
|
|||
|
||||
def test_import_students(self):
|
||||
"""
|
||||
Import of the main students file.
|
||||
Import CLOEE file for FE students (ASAFE, ASEFE, ASSCF, EDE, EDS) version 2018!!
|
||||
|
||||
Student :
|
||||
- S. Lampion, 1ASSCFEa
|
||||
- T. Tournesol, 1EDS18-20
|
||||
|
||||
Candidate:
|
||||
- B. Castafiore, 2EDEpe
|
||||
|
||||
Export CLOEE:
|
||||
- S. Lampion, 2ASSFEa
|
||||
- B. Castafiore, 2EDEpe
|
||||
- A. Haddock, 2EDS18-20
|
||||
|
||||
Results in Student:
|
||||
- S. Lampion, 2ASSFEa (Student data + Cloee klass)
|
||||
- B. Castafiore, 2EDEpe (Candidate data + Cloee klass)
|
||||
- A. Haddock, 2EDS18-20 (Cloee data) + Warning!
|
||||
- T. Tournesol, archived
|
||||
"""
|
||||
lev1 = Level.objects.create(name='1')
|
||||
lev2 = Level.objects.create(name='2')
|
||||
assc = Section.objects.create(name='ASSC')
|
||||
Option.objects.create(name='Accompagnement des enfants')
|
||||
k1 = Klass.objects.create(name='1ASSCFEa', section=assc, level=lev1)
|
||||
inst = CorpContact.objects.create(first_name="Roberto", last_name="Rastapopoulos")
|
||||
Candidate.objects.create(
|
||||
first_name="Bianca", last_name="Castafiore", deposite_date="2018-06-06",
|
||||
option='ENF', instructor=inst
|
||||
)
|
||||
# An existing student, klass should be changed.
|
||||
Student.objects.create(ext_id=11111, first_name="Séraphin", last_name="Lampion", klass=k1)
|
||||
|
||||
|
|
@ -474,11 +499,12 @@ class ImportTests(TestCase):
|
|||
|
||||
student1 = Student.objects.get(ext_id=11111)
|
||||
self.assertEqual(student1.klass.name, '2ASSCFEa')
|
||||
student2 = Student.objects.get(ext_id=22222)
|
||||
self.assertEqual(student2.corporation.name, 'Accueil Haut les mains')
|
||||
self.assertFalse(student2.dispense_eps)
|
||||
# Instructor not set through this import
|
||||
self.assertIsNone(student2.instructor)
|
||||
# New student from existing candidate.
|
||||
student_cand = Student.objects.get(ext_id=22222)
|
||||
self.assertEqual(student_cand.instructor.last_name, 'Rastapopoulos')
|
||||
self.assertEqual(student_cand.option_ase.name, 'Accompagnement des enfants')
|
||||
self.assertEqual(student_cand.corporation.name, 'Accueil Haut les mains')
|
||||
self.assertFalse(student_cand.dispense_eps)
|
||||
|
||||
def test_import_hp(self):
|
||||
teacher = Teacher.objects.create(
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ from django.shortcuts import get_object_or_404
|
|||
from django.urls import reverse
|
||||
from django.views.generic import FormView
|
||||
|
||||
from candidats.models import Candidate
|
||||
from ..forms import StudentImportForm, UploadHPFileForm, UploadReportForm
|
||||
from ..models import (
|
||||
Corporation, CorpContact, Course, Klass, Option, Student, Teacher,
|
||||
|
|
@ -98,6 +99,12 @@ class StudentImportView(ImportViewBase):
|
|||
'ENT_TEL': 'tel',
|
||||
'ENT_CODE_CANTON' : 'district',
|
||||
}
|
||||
mapping_option_ase = {
|
||||
'GEN': 'Généraliste',
|
||||
'ENF': 'Accompagnement des enfants',
|
||||
'HAN': 'Accompagnement des personnes handicapées',
|
||||
'PAG': 'Accompagnement des personnes âgées',
|
||||
}
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super().get_form_kwargs()
|
||||
|
|
@ -139,6 +146,7 @@ class StudentImportView(ImportViewBase):
|
|||
return val.strip() if isinstance(val, str) else val
|
||||
|
||||
obj_created = obj_modified = 0
|
||||
err_msg = []
|
||||
seen_students_ids = set()
|
||||
for line in up_file:
|
||||
student_defaults = {
|
||||
|
|
@ -169,10 +177,31 @@ class StudentImportView(ImportViewBase):
|
|||
student.save()
|
||||
obj_modified += 1
|
||||
except Student.DoesNotExist:
|
||||
student = Student.objects.create(**defaults)
|
||||
obj_created += 1
|
||||
try:
|
||||
candidate = Candidate.objects.get(last_name=defaults['last_name'],
|
||||
first_name=defaults['first_name'])
|
||||
# Mix CLOEE data and Candidate data
|
||||
if candidate.option in self.mapping_option_ase:
|
||||
defaults['option_ase'] = Option.objects.get(name=self.mapping_option_ase[candidate.option])
|
||||
if candidate.corporation:
|
||||
defaults['corporation'] = candidate.corporation
|
||||
defaults['instructor'] = candidate.instructor
|
||||
defaults['dispense_ecg'] = candidate.exemption_ecg
|
||||
defaults['soutien_dys'] = candidate.handicap
|
||||
Student.objects.create(**defaults)
|
||||
obj_created += 1
|
||||
except Candidate.DoesNotExist:
|
||||
# New student with no matching Candidate
|
||||
err_msg.append('Étudiant non trouvé dans les candidats: {0} {1} - classe: {2}'.format(
|
||||
defaults['last_name'],
|
||||
defaults['first_name'],
|
||||
defaults['klass'])
|
||||
)
|
||||
Student.objects.create(**defaults)
|
||||
obj_created += 1
|
||||
|
||||
# FIXME: implement arch_staled
|
||||
return {'created': obj_created, 'modified': obj_modified}
|
||||
return {'created': obj_created, 'modified': obj_modified, 'errors': err_msg}
|
||||
|
||||
def get_corporation(self, corp_values):
|
||||
if corp_values['ext_id'] == '':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue