diff --git a/stages/test_files/HYPERPLANNING.txt b/stages/test_files/HYPERPLANNING.csv similarity index 95% rename from stages/test_files/HYPERPLANNING.txt rename to stages/test_files/HYPERPLANNING.csv index a5a7d81..0a85f99 100644 --- a/stages/test_files/HYPERPLANNING.txt +++ b/stages/test_files/HYPERPLANNING.csv @@ -29,3 +29,4 @@ Dupond Jeanne;;Sém. enfance 2;[2ASEFE c-d E S2];8.00 Dupond Jeanne;;Sém. enfance 2;[2ASEFE c-d E S2];8.00 Dupond Jeanne;;Sém. enfance 2;[2ASEFE c-d E S2];8.00 Dupond Jeanne;;Travail personnel;[2ASEFE c-d E S2];1'054.00 +Nom Inconnu;;Autre travail;3MPS ASE1;8.00 diff --git a/stages/tests.py b/stages/tests.py index 6867924..0d089e7 100644 --- a/stages/tests.py +++ b/stages/tests.py @@ -465,12 +465,13 @@ class ImportTests(TestCase): teacher = Teacher.objects.create( first_name='Jeanne', last_name='Dupond', birth_date='1974-08-08' ) - path = os.path.join(os.path.dirname(__file__), 'test_files', 'HYPERPLANNING.txt') + path = os.path.join(os.path.dirname(__file__), 'test_files', 'HYPERPLANNING.csv') self.client.login(username='me', password='mepassword') with open(path, 'rb') as fh: response = self.client.post(reverse('import-hp'), {'upload': fh}, follow=True) self.assertContains(response, "Objets créés : 13") self.assertContains(response, "Objets modifiés : 10") + self.assertContains(response, "Impossible de trouver «Nom Inconnu» dans la liste des enseignant-e-s") self.assertEqual(teacher.course_set.count(), 13) def test_import_hp_contacts(self): diff --git a/stages/views.py b/stages/views.py index 2fe2b22..8243c92 100644 --- a/stages/views.py +++ b/stages/views.py @@ -422,8 +422,16 @@ class HPImportView(ImportViewBase): if (line['LIBELLE_MAT'] == '' or line['NOMPERSO_DIP'] == '' or line['TOTAL'] == ''): continue + try: + teacher = profs[line['NOMPERSO_ENS']] + except KeyError: + errors.append( + "Impossible de trouver «%s» dans la liste des enseignant-e-s" % line['NOMPERSO_ENS'] + ) + continue + obj, created = Course.objects.get_or_create( - teacher=profs[line['NOMPERSO_ENS']], + teacher=teacher, subject=line['LIBELLE_MAT'], public=line['NOMPERSO_DIP'], )