diff --git a/stages/test_files/Export_HP_Formateurs.xlsx b/stages/test_files/Export_HP_Formateurs.xlsx index 93a9b6e..d14ea9b 100644 Binary files a/stages/test_files/Export_HP_Formateurs.xlsx and b/stages/test_files/Export_HP_Formateurs.xlsx differ diff --git a/stages/tests.py b/stages/tests.py index 30c2cf8..85efa2b 100644 --- a/stages/tests.py +++ b/stages/tests.py @@ -326,10 +326,15 @@ class ImportTests(TestCase): st1 = Student.objects.create( ext_id=164718, first_name='Margot', last_name='Fellmann', birth_date="1994-05-12", pcode="2300", city="La Chaux-de-Fonds", corporation=corp) + Student.objects.create( + ext_id=53476, first_name='Jojo', last_name='Semaine', birth_date="1997-01-03", + pcode="2300", city="La Chaux-de-Fonds", corporation=None) path = os.path.join(os.path.dirname(__file__), 'test_files', 'Export_HP_Formateurs.xlsx') self.client.login(username='me', password='mepassword') with open(path, 'rb') as fh: response = self.client.post(reverse('import-hp-contacts'), {'upload': fh}, follow=True) + self.assertContains(response, "Impossible de trouver l'étudiant avec le numéro 10") + self.assertContains(response, "NoSIRET est vide à ligne 4. Ligne ignorée") st1.refresh_from_db() self.assertEqual(st1.instructor.last_name, 'Geiser') diff --git a/stages/views.py b/stages/views.py index aef6eee..2857d99 100644 --- a/stages/views.py +++ b/stages/views.py @@ -457,7 +457,7 @@ class HPContactsImportView(ImportViewBase): def import_data(self, up_file): obj_modified = 0 errors = [] - for line in up_file: + for idx, line in enumerate(up_file, start=2): try: student = Student.objects.get(ext_id=int(line['UID_ETU'])) except Student.DoesNotExist: @@ -465,6 +465,11 @@ class HPContactsImportView(ImportViewBase): "Impossible de trouver l'étudiant avec le numéro %s" % int(line['UID_ETU']) ) continue + if not line['NoSIRET']: + errors.append( + "NoSIRET est vide à ligne %d. Ligne ignorée" % idx + ) + continue try: corp = Corporation.objects.get(ext_id=int(line['NoSIRET'])) except Corporation.DoesNotExist: