Don't crash if CSV web importer does not receive a file
This commit is contained in:
parent
b3d94ab608
commit
ad0a1aa44a
1 changed files with 10 additions and 3 deletions
|
@ -1,10 +1,12 @@
|
|||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required, user_passes_test
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render
|
||||
from todo.operations.csv_importer import CSVImporter
|
||||
from django.shortcuts import redirect, render, reverse
|
||||
|
||||
from todo.operations.csv_importer import CSVImporter
|
||||
from todo.utils import staff_check
|
||||
|
||||
|
||||
@login_required
|
||||
@user_passes_test(staff_check)
|
||||
def import_csv(request) -> HttpResponse:
|
||||
|
@ -14,7 +16,12 @@ def import_csv(request) -> HttpResponse:
|
|||
ctx = {}
|
||||
|
||||
if request.method == "POST":
|
||||
filepath = request.FILES.get('csvfile')
|
||||
filepath = request.FILES.get("csvfile")
|
||||
|
||||
if not filepath:
|
||||
messages.error(request, "You must supply a CSV file to import.")
|
||||
return redirect(reverse("todo:import_csv"))
|
||||
|
||||
importer = CSVImporter()
|
||||
results = importer.upsert(filepath)
|
||||
ctx["results"] = results
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue