Merge pull request #1925 from alphagov/refactored-csv-processing

Bring in refactored CSV processing
This commit is contained in:
Chris Hill-Scott
2018-03-09 15:16:37 +00:00
committed by GitHub
8 changed files with 79 additions and 53 deletions

View File

@@ -528,29 +528,23 @@ def _check_messages(service_id, template_type, upload_id, preview_row, letters_a
back_link = url_for('.send_messages', service_id=service_id, template_id=template.id)
choose_time_form = ChooseTimeForm()
count_of_recipients = len(list(recipients.rows))
if preview_row < 2:
abort(404)
if preview_row < count_of_recipients + 2:
template.values = recipients[preview_row - 2]
if preview_row < len(recipients) + 2:
template.values = recipients[preview_row - 2].recipient_and_personalisation
elif preview_row > 2:
abort(404)
session['upload_data']['notification_count'] = count_of_recipients
session['upload_data']['notification_count'] = len(recipients)
session['upload_data']['valid'] = not recipients.has_errors
return dict(
recipients=recipients,
template=template,
errors=recipients.has_errors,
row_errors=get_errors_for_csv(recipients, template.template_type),
count_of_recipients=count_of_recipients,
count_of_displayed_recipients=(
len(list(recipients.initial_annotated_rows_with_errors))
if any(recipients.rows_with_errors) and not recipients.missing_column_headers else
len(list(recipients.initial_annotated_rows))
),
count_of_recipients=len(recipients),
count_of_displayed_recipients=len(list(recipients.displayed_rows)),
original_file_name=session['upload_data'].get('original_file_name'),
upload_id=upload_id,
form=CsvUploadForm(),