mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-15 07:18:58 -04:00
Refactor to use address validation in utils
This commit is contained in:
@@ -112,17 +112,9 @@ def send_messages(service_id, template_id):
|
||||
form = CsvUploadForm()
|
||||
if form.validate_on_submit():
|
||||
try:
|
||||
file_data = Spreadsheet.from_file(form.file.data, filename=form.file.data.filename).as_dict
|
||||
if template.template_type == 'letter':
|
||||
def is_ascii(s):
|
||||
return all(ord(c) < 128 for c in s)
|
||||
|
||||
if is_ascii(str(file_data)) is False:
|
||||
raise ValueError("Invalid characters in {}".format(form.file.data.filename))
|
||||
|
||||
upload_id = s3upload(
|
||||
service_id,
|
||||
file_data,
|
||||
Spreadsheet.from_file(form.file.data, filename=form.file.data.filename).as_dict,
|
||||
current_app.config['AWS_REGION']
|
||||
)
|
||||
session['upload_data'] = {
|
||||
@@ -137,10 +129,6 @@ def send_messages(service_id, template_id):
|
||||
flash('Couldn’t read {}. Try using a different file format.'.format(
|
||||
form.file.data.filename
|
||||
))
|
||||
except ValueError:
|
||||
flash('Invalid characters in the address fields within {}.'.format(
|
||||
form.file.data.filename
|
||||
))
|
||||
|
||||
column_headings = first_column_headings[template.template_type] + list(template.placeholders)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user