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

moved voter files to content

parent f1b46067
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,7 @@ from django.utils import simplejson ...@@ -11,7 +11,7 @@ from django.utils import simplejson
from django.conf import settings from django.conf import settings
from django.core.mail import send_mail from django.core.mail import send_mail
import datetime, logging, uuid, random import datetime, logging, uuid, random, StringIO
from crypto import electionalgs, algs, utils from crypto import electionalgs, algs, utils
from helios import utils as heliosutils from helios import utils as heliosutils
...@@ -219,11 +219,14 @@ class Election(HeliosModel): ...@@ -219,11 +219,14 @@ 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...
""" """
random_filename = str(uuid.uuid4()) # now we're just storing the content
new_voter_file = VoterFile(election = self) # random_filename = str(uuid.uuid4())
new_voter_file.voter_file.save(random_filename, uploaded_file) # new_voter_file.voter_file.save(random_filename, uploaded_file)
self.append_log(ElectionLog.VOTER_FILE_ADDED)
new_voter_file = VoterFile(election = self, voter_file_content = uploaded_file.read())
new_voter_file.save()
self.append_log(ElectionLog.VOTER_FILE_ADDED)
return new_voter_file return new_voter_file
def user_eligible_p(self, user): def user_eligible_p(self, user):
...@@ -636,7 +639,12 @@ class VoterFile(models.Model): ...@@ -636,7 +639,12 @@ class VoterFile(models.Model):
num_voters = models.IntegerField(null=True) num_voters = models.IntegerField(null=True)
def itervoters(self): def itervoters(self):
reader = unicode_csv_reader(open(self.voter_file.path, "rU")) if self.voter_file_content:
voter_stream = StringIO.StringIO(self.voter_file_content)
else:
voter_stream = open(self.voter_file.path, "rU")
reader = unicode_csv_reader(voter_stream)
for voter_fields in reader: for voter_fields in reader:
# bad line # bad line
...@@ -658,7 +666,14 @@ class VoterFile(models.Model): ...@@ -658,7 +666,14 @@ class VoterFile(models.Model):
self.save() self.save()
election = self.election election = self.election
reader = unicode_csv_reader(open(self.voter_file.path, "rU"))
# now we're looking straight at the content
if self.voter_file_content:
voter_stream = StringIO.StringIO(self.voter_file_content)
else:
voter_stream = open(self.voter_file.path, "rU")
reader = unicode_csv_reader(voter_stream)
last_alias_num = election.last_alias_num last_alias_num = election.last_alias_num
......
...@@ -588,10 +588,7 @@ class ElectionBlackboxTests(WebTest): ...@@ -588,10 +588,7 @@ class ElectionBlackboxTests(WebTest):
# vote by preparing a ballot via the server-side encryption # vote by preparing a ballot via the server-side encryption
response = self.app.post("/helios/elections/%s/encrypt-ballot" % election_id, { response = self.app.post("/helios/elections/%s/encrypt-ballot" % election_id, {
'answers_json': utils.to_json([[1]])}) 'answers_json': utils.to_json([[1]])})
try:
self.assertContains(response, "answers") self.assertContains(response, "answers")
except:
import pdb; pdb.set_trace()
# parse it as an encrypted vote with randomness, and make sure randomness is there # parse it as an encrypted vote with randomness, and make sure randomness is there
the_ballot = utils.from_json(response.testbody) the_ballot = utils.from_json(response.testbody)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment