Lookup index, rather than iterating

Since instances of `Recipients` are now iterable we can just look up the
first row by index, rather than having to hit the rows property as a
generator.

There is a chance that there won’t be a first row, if the file has 1 or
fewer columns. So we still need to handle a possible exception (albeit
it a different one to before).
This commit is contained in:
Chris Hill-Scott
2017-12-06 22:00:45 +00:00
parent 3e5deeffdb
commit 587e18d2ef

View File

@@ -521,8 +521,8 @@ def _check_messages(service_id, template_type, upload_id, letters_as_pdf=False):
back_link = url_for('.send_messages', service_id=service_id, template_id=template.id)
choose_time_form = ChooseTimeForm()
with suppress(StopIteration):
template.values = next(recipients.rows)
with suppress(IndexError):
template.values = recipients[0]
session['upload_data']['notification_count'] = len(list(recipients.rows))
session['upload_data']['valid'] = not recipients.has_errors