Fixed HP import crash if teacher name not found
This commit is contained in:
parent
d9b714ceca
commit
d180c6ec7b
3 changed files with 12 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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'],
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue