Skip to content
Snippets Groups Projects
Commit 3c61f7a6 authored by Ben Adida's avatar Ben Adida
Browse files

added extra error handling

parent 5502f694
Branches
Tags
No related merge requests found
...@@ -14,11 +14,16 @@ You have uploaded a file of voters. The first few rows of this file are: ...@@ -14,11 +14,16 @@ You have uploaded a file of voters. The first few rows of this file are:
{% endfor %} {% endfor %}
</table> </table>
{% if email_problem %} {% if problems %}
<p style="font-size: 1.5em;"> <p style="font-size: 1.5em;">
<b>HOLD ON</b>: those don't look like correct email addresses. Are you sure you uploaded a file with email address as second field?<br /> HOLD ON:<br />
{% for problem in problems %}
- {{problem}}<br />
{% endfor %}
</p>
<br />
<a href="{% url helios.views.voters_upload_cancel election.uuid %}">no, let me upload a different file</a> <a href="{% url helios.views.voters_upload_cancel election.uuid %}">never mind, upload a different file</a>
</p> </p>
{% else %} {% else %}
......
...@@ -1230,13 +1230,20 @@ def voters_upload(request, election): ...@@ -1230,13 +1230,20 @@ def voters_upload(request, election):
request.session['voter_file_id'] = voter_file_obj.id request.session['voter_file_id'] = voter_file_obj.id
problems = []
# import the first few lines to check # import the first few lines to check
try:
voters = [v for v in voter_file_obj.itervoters()][:5] voters = [v for v in voter_file_obj.itervoters()][:5]
except:
voters = []
problems.append("your CSV file could not be processed. Please check that it is a proper CSV file.")
# check if voter emails look like emails # check if voter emails look like emails
email_problem = False in [validate_email(v['email']) for v in voters] if False in [validate_email(v['email']) for v in voters]:
problems.append("those don't look like correct email addresses. Are you sure you uploaded a file with email address as second field?")
return render_template(request, 'voters_upload_confirm', {'election': election, 'voters': voters, 'email_problem': email_problem}) return render_template(request, 'voters_upload_confirm', {'election': election, 'voters': voters, 'problems': problems})
else: else:
return HttpResponseRedirect("%s?%s" % (settings.SECURE_URL_HOST + reverse(voters_upload, args=[election.uuid]), urllib.urlencode({'e':'no voter file specified, try again'}))) return HttpResponseRedirect("%s?%s" % (settings.SECURE_URL_HOST + reverse(voters_upload, args=[election.uuid]), urllib.urlencode({'e':'no voter file specified, try again'})))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment