From 906701c2b364bf7a7358732ef8ccfd4a6534ef8a Mon Sep 17 00:00:00 2001 From: Ben Adida <ben@adida.net> Date: Wed, 9 Mar 2011 20:50:26 -0800 Subject: [PATCH] added new statistics and stripping of CSV values in import, plus appropriate test --- helios/fixtures/voter-file.csv | 2 +- helios/models.py | 6 +++--- helios/templates/stats_problem_elections.html | 15 +++++++++++++++ helios/tests.py | 5 +++++ 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 helios/templates/stats_problem_elections.html diff --git a/helios/fixtures/voter-file.csv b/helios/fixtures/voter-file.csv index 7a6a77d..8bb842d 100644 --- a/helios/fixtures/voter-file.csv +++ b/helios/fixtures/voter-file.csv @@ -1,4 +1,4 @@ -benadida5,ben5@adida.net,Ben5 Adida + benadida5,ben5@adida.net , Ben5 Adida benadida6,ben6@adida.net,Ben6 Adida benadida7,ben7@adida.net,Ben7 Adida benadida8,ben8@adida.net,Ben8 Adida diff --git a/helios/models.py b/helios/models.py index e772a1f..b0d722f 100644 --- a/helios/models.py +++ b/helios/models.py @@ -612,15 +612,15 @@ class VoterFile(models.Model): continue num_voters += 1 - voter_id = voter[0] + voter_id = voter[0].strip() name = voter_id email = voter_id if len(voter) > 1: - email = voter[1] + email = voter[1].strip() if len(voter) > 2: - name = voter[2] + name = voter[2].strip() # create the user -- NO MORE # user = User.update_or_create(user_type='password', user_id=email, info = {'name': name}) diff --git a/helios/templates/stats_problem_elections.html b/helios/templates/stats_problem_elections.html new file mode 100644 index 0000000..341e375 --- /dev/null +++ b/helios/templates/stats_problem_elections.html @@ -0,0 +1,15 @@ +{% extends TEMPLATE_BASE %} +{% block title %}Statistics{% endblock %} + +{% block content %} +<h1>Problematic Elections</h1> + +Unfrozen for more than a day. + +{% for election in elections %} +<p> +<b><a href="{% url helios.views.one_election_view election.uuid %}">{{election.name}}</a></b> -- {{election.num_voters}} voters +</p> +{% endfor %} + +{% endblock %} diff --git a/helios/tests.py b/helios/tests.py index a563ef7..340d525 100644 --- a/helios/tests.py +++ b/helios/tests.py @@ -78,6 +78,11 @@ class ElectionModelTests(TestCase): vf = models.VoterFile.objects.create(election = election, voter_file = File(open(FILE), "voter_file.css")) vf.process() + # make sure that we stripped things correctly + voter = election.voter_set.get(voter_login_id = 'benadida5') + self.assertEquals(voter.voter_email, 'ben5@adida.net') + self.assertEquals(voter.voter_name, 'Ben5 Adida') + def test_check_issues_before_freeze(self): # should be three issues: no trustees, and no questions, and no voters issues = self.election.issues_before_freeze -- GitLab