diff --git a/common/settings.py b/common/settings.py index 5096813..4f098d8 100644 --- a/common/settings.py +++ b/common/settings.py @@ -130,6 +130,7 @@ STUDENT_IMPORT_MAPPING = { 'NAVS13': 'avs', 'SEXE': 'gender', 'CLASSE_ACTUELLE': 'klass', + 'LIB_BRANCHE_OPTION': 'option_ase', } CORPORATION_IMPORT_MAPPING = { diff --git a/stages/test_files/EXPORT_GAN.xlsx b/stages/test_files/EXPORT_GAN.xlsx index 9e22173..b227634 100644 Binary files a/stages/test_files/EXPORT_GAN.xlsx and b/stages/test_files/EXPORT_GAN.xlsx differ diff --git a/stages/tests.py b/stages/tests.py index 31a7616..010bd97 100644 --- a/stages/tests.py +++ b/stages/tests.py @@ -9,7 +9,7 @@ from django.urls import reverse from django.utils.html import escape from .models import ( - Level, Domain, Section, Klass, Period, Student, Corporation, Availability, + Level, Domain, Section, Klass, Option, Period, Student, Corporation, Availability, CorpContact, Teacher, Training, Course, ) from .utils import school_year @@ -282,7 +282,10 @@ class ImportTests(TestCase): def setUp(self): User.objects.create_user('me', 'me@example.org', 'mepassword') - def test_import_gan(self): + def test_import_students(self): + """ + Import of the main students file. + """ path = os.path.join(os.path.dirname(__file__), 'test_files', 'EXPORT_GAN.xlsx') self.client.login(username='me', password='mepassword') with open(path, 'rb') as fh: @@ -301,12 +304,14 @@ class ImportTests(TestCase): section=Section.objects.create(name='EDE'), level=lev1, ) + Option.objects.create(name='Accompagnement des enfants') with open(path, 'rb') as fh: # , override_settings(DEBUG=True): response = self.client.post(reverse('import-students'), {'upload': fh}, follow=True) msg = "\n".join(str(m) for m in response.context['messages']) self.assertIn("Objets créés : 2", msg) student1 = Student.objects.get(last_name='Fellmann') self.assertEqual(student1.corporation.name, "Crèche Les Mousaillons") + self.assertEqual(student1.option_ase.name, "Accompagnement des enfants") # Instructor not set through this import self.assertIsNone(student1.instructor) diff --git a/stages/views.py b/stages/views.py index 7c14ccf..69b5305 100644 --- a/stages/views.py +++ b/stages/views.py @@ -23,7 +23,7 @@ from django.views.generic import DetailView, FormView, TemplateView, ListView from .forms import PeriodForm, StudentImportForm, UploadHPFileForm from .models import ( - Klass, Section, Student, Teacher, Corporation, CorpContact, Course, Period, + Klass, Section, Option, Student, Teacher, Corporation, CorpContact, Course, Period, Training, Availability, ) from .pdf import UpdateDataFormPDF @@ -342,6 +342,11 @@ class StudentImportView(ImportViewBase): seen_students_ids.add(student_defaults['ext_id']) if isinstance(student_defaults['birth_date'], str): student_defaults['birth_date'] = datetime.strptime(student_defaults['birth_date'], '%d.%m.%Y').date() + if student_defaults['option_ase']: + try: + student_defaults['option_ase'] = Option.objects.get(name=student_defaults['option_ase']) + except Option.DoesNotExist: + del student_defaults['option_ase'] corporation_defaults = { val: strip(line[key]) for key, val in corporation_mapping.items()