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.contrib.auth.decorators import login_required, user_passes_test
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import render
|
from django.shortcuts import redirect, render, reverse
|
||||||
from todo.operations.csv_importer import CSVImporter
|
|
||||||
|
|
||||||
|
from todo.operations.csv_importer import CSVImporter
|
||||||
from todo.utils import staff_check
|
from todo.utils import staff_check
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@user_passes_test(staff_check)
|
@user_passes_test(staff_check)
|
||||||
def import_csv(request) -> HttpResponse:
|
def import_csv(request) -> HttpResponse:
|
||||||
|
@ -14,7 +16,12 @@ def import_csv(request) -> HttpResponse:
|
||||||
ctx = {}
|
ctx = {}
|
||||||
|
|
||||||
if request.method == "POST":
|
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()
|
importer = CSVImporter()
|
||||||
results = importer.upsert(filepath)
|
results = importer.upsert(filepath)
|
||||||
ctx["results"] = results
|
ctx["results"] = results
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue