Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Helios Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Helios Server
Commits
b7243dcc
Commit
b7243dcc
authored
4 years ago
by
Ben Adida
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
helios/fixtures/voter-file-latin1.csv
+4
-0
4 additions, 0 deletions
helios/fixtures/voter-file-latin1.csv
helios/models.py
+8
-4
8 additions, 4 deletions
helios/models.py
helios/tests.py
+7
-0
7 additions, 0 deletions
helios/tests.py
with
19 additions
and
4 deletions
helios/fixtures/voter-file-latin1.csv
0 → 100644
+
4
−
0
View file @
b7243dcc
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
This diff is collapsed.
Click to expand it.
helios/models.py
+
8
−
4
View file @
b7243dcc
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
helios/tests.py
+
7
−
0
View file @
b7243dcc
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment