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

allow for uploading of a latin1-encoded voter file, not just utf-8

parent bc093712
No related branches found
No related tags found
No related merge requests found
benadida5,ben5@adida.net , Ben5 Adida
benadida6,ben6@adida.net,Ben6 Adida
benadida7,ben7@adida.net,Ben7 Adida
testlatin1,Test Latin1,JÂNIO LUIZ CORREIA JÚNIOR
...@@ -272,11 +272,15 @@ class Election(HeliosModel): ...@@ -272,11 +272,15 @@ class Election(HeliosModel):
""" """
expects a django uploaded_file data structure, which has filename, content, size... expects a django uploaded_file data structure, which has filename, content, size...
""" """
# now we're just storing the content voter_file_content_bytes = uploaded_file.read()
# random_filename = str(uuid.uuid4())
# new_voter_file.voter_file.save(random_filename, uploaded_file)
new_voter_file = VoterFile(election = self, voter_file_content = uploaded_file.read()) # usually it's utf-8 encoded, but occasionally it's latin-1
try:
voter_file_content = voter_file_content_bytes.decode('utf-8')
except:
voter_file_content = voter_file_content_bytes.decode('latin-1')
new_voter_file = VoterFile(election = self, voter_file_content = voter_file_content)
new_voter_file.save() new_voter_file.save()
self.append_log(ElectionLog.VOTER_FILE_ADDED) self.append_log(ElectionLog.VOTER_FILE_ADDED)
......
...@@ -585,6 +585,13 @@ class ElectionBlackboxTests(WebTest): ...@@ -585,6 +585,13 @@ class ElectionBlackboxTests(WebTest):
response = self.client.post("/helios/elections/%s/voters/upload" % election_id, {'confirm_p': "1"}) response = self.client.post("/helios/elections/%s/voters/upload" % election_id, {'confirm_p': "1"})
self.assertRedirects(response, "/helios/elections/%s/voters/list" % election_id) self.assertRedirects(response, "/helios/elections/%s/voters/list" % election_id)
# Try a latin-1 encoded file
FILE = "helios/fixtures/voter-file-latin1.csv"
voters_file = open(FILE, mode='rb')
response = self.client.post("/helios/elections/%s/voters/upload" % election_id, {'voters_file': voters_file})
voters_file.close()
self.assertContains(response, "first few rows of this file")
# and we want to check that there are now voters # and we want to check that there are now voters
response = self.client.get("/helios/elections/%s/voters/" % election_id) response = self.client.get("/helios/elections/%s/voters/" % election_id)
NUM_VOTERS = 4 NUM_VOTERS = 4
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment