Skip to content

Commit

Permalink
Improve error handling for web upload of bad CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
shacker committed Apr 2, 2019
1 parent ad0a1aa commit e9a7bbe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions todo/operations/csv_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ def upsert(self, fileobj, as_string_obj=False):
"Priority",
]
if header != expected:
self.results.get("summaries").append(
self.errors.append(
f"Inbound data does not have expected columns.\nShould be: {expected}"
)
return self.results
return

for row in csv_reader:
self.line_count += 1
Expand Down
8 changes: 7 additions & 1 deletion todo/views/import_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def import_csv(request) -> HttpResponse:

importer = CSVImporter()
results = importer.upsert(filepath)
ctx["results"] = results

ctx["results"] = None
if results:
ctx["results"] = results
else:
messages.error(request, "Could not parse provided CSV file.")
return redirect(reverse("todo:import_csv"))

return render(request, "todo/import_csv.html", context=ctx)

0 comments on commit e9a7bbe

Please sign in to comment.