Merge pull request #1911 from alphagov/fix-date-exception

Catch exceptions caused by ambiguous Excel files
This commit is contained in:
Chris Hill-Scott
2018-03-02 12:46:26 +00:00
committed by GitHub
2 changed files with 74 additions and 2 deletions

View File

@@ -22,6 +22,7 @@ from notifications_utils.recipients import (
from orderedset import OrderedSet
from werkzeug.routing import RequestRedirect
from xlrd.biffh import XLRDError
from xlrd.xldate import XLDateError
from app import (
current_service,
@@ -137,6 +138,13 @@ def send_messages(service_id, template_id):
flash('Couldnt read {}. Try using a different file format.'.format(
form.file.data.filename
))
except (XLDateError):
flash((
'{} contains numbers or dates that Notify cant understand. '
'Try formatting all columns as text or export your file as CSV.'
).format(
form.file.data.filename
))
column_headings = first_column_headings[template.template_type] + list(template.placeholders)