Skip to content

Commit 8b3e3f2

Browse files
committed
Fixed 500 when uploading blank spreadsheet
Fixed burke-software#22
1 parent 7a5f80c commit 8b3e3f2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

simple_import/views.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.contrib.contenttypes.models import ContentType
33
from django.contrib.admin.models import LogEntry, ADDITION, CHANGE
44
from django.contrib.admin.views.decorators import staff_member_required
5+
from django.contrib import messages
56
from django.conf import settings
67
from django.core.exceptions import SuspiciousOperation
78
from django.core.urlresolvers import reverse
@@ -11,7 +12,7 @@
1112
from django.core.exceptions import ObjectDoesNotExist
1213
from django.forms.models import inlineformset_factory
1314
from django.http import HttpResponseRedirect
14-
from django.shortcuts import render_to_response, get_object_or_404
15+
from django.shortcuts import render_to_response, get_object_or_404, redirect
1516
from django.template import RequestContext
1617
import sys
1718
from django.db.models.fields import AutoField
@@ -82,7 +83,12 @@ def match_columns(request, import_log_id):
8283

8384
import_data = import_log.get_import_file_as_list()
8485
header_row = [x.lower() for x in import_data[0]] # make all lower
85-
sample_row = import_data[1]
86+
try:
87+
sample_row = import_data[1]
88+
except IndexError:
89+
messages.error(request, 'Error: Spreadsheet was empty.')
90+
return redirect('simple_import-start_import')
91+
8692
errors = []
8793

8894
model_class = import_log.import_setting.content_type.model_class()

0 commit comments

Comments
 (0)