Do some checks to make sure we've got a csv file on import.

Fixes #104.
This commit is contained in:
Adam Kelly
2020-04-29 15:33:06 +01:00
parent 4f9edae05a
commit aec8e5c536
2 changed files with 11 additions and 4 deletions

View File

@ -14,6 +14,8 @@ MAX_ENTRIES = 20
def create_job(user, csv_file):
job = ImportJob.objects.create(user=user)
for index, entry in enumerate(list(csv.DictReader(csv_file))[:MAX_ENTRIES]):
if not all(x in entry for x in ('ISBN13', 'Title', 'Author')):
raise ValueError("Author, title, and isbn must be in data.")
ImportItem(job=job, index=index, data=entry).save()
return job