Report error when NoSIRET column is empty in HPContactsImportView
This commit is contained in:
parent
b81d7db5b3
commit
c86128250e
3 changed files with 11 additions and 1 deletions
Binary file not shown.
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue