From 06fbfc2efb8e2271a5a771b2f83edf7aa3dcdb5a Mon Sep 17 00:00:00 2001
From: Ben Adida <ben@adida.net>
Date: Mon, 30 Aug 2010 20:39:26 -0700
Subject: [PATCH] merged voter list and bboard

---
 helios/templates/election_view.html |  4 ++--
 helios/templates/voters_list.html   | 10 +++++++---
 helios/views.py                     | 10 +++++++++-
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/helios/templates/election_view.html b/helios/templates/election_view.html
index 59c6d59..6578b0c 100644
--- a/helios/templates/election_view.html
+++ b/helios/templates/election_view.html
@@ -59,7 +59,7 @@ this election is <u>not</u> featured on the front page.
 <p align="center" style="font-size: 1.5em;">
 <a href="{% url helios.views.one_election_questions election.uuid %}">questions ({% if election.questions %}{{election.questions|length}}{% else %}0{% endif %})</a>
 &nbsp;&nbsp;|&nbsp;&nbsp;
-<a href="{% url helios.views.voters_list_pretty election.uuid %}">voters</a>
+<a href="{% url helios.views.voters_list_pretty election.uuid %}">voters &amp; ballots</a>
 &nbsp;&nbsp;|&nbsp;&nbsp;
 <a href="{% url helios.views.list_trustees_view election.uuid %}">trustees ({{trustees|length}})</a>
 </p>
@@ -241,7 +241,7 @@ You are <em>not eligible</em> to vote in this election, because registration is
 {% endif %}
 
 <p style="font-size: 1.3em;">
-<a href="{% url helios.views.one_election_bboard election.uuid %}">Ballot Tracking Center</a> &nbsp;| &nbsp;
+<a href="{% url helios.views.voters_list_pretty election.uuid %}">Ballot Tracking Center</a> &nbsp;| &nbsp;
 <a href="{% url helios.views.one_election_audited_ballots election.uuid %}">Audited Ballots</a>
 </p>
 
diff --git a/helios/templates/voters_list.html b/helios/templates/voters_list.html
index e0dfc63..d796895 100644
--- a/helios/templates/voters_list.html
+++ b/helios/templates/voters_list.html
@@ -21,7 +21,11 @@
 
 
 <p>
+{% if q %}
+<p><em>searching for <u>{{q}}</u>.</em> [<a href="?">clear search</a>]</p>
+{% else %}
 <form method="get" action="{% url helios.views.voters_list_pretty election.uuid %}"><b>search</b>: <input type="text" name="q" /> <input type="submit" value="search" /></form>
+{% endif %}
 </p>
 <br />
 {% if admin_p and upload_p %}
@@ -56,13 +60,13 @@ Prior Bulk Uploads:
 {% if voters %}
 
 {% if voters_page.has_previous %}
-<a href="./list?page={{voters_page.previous_page_number}}&limit={{limit}}">previous {{limit}}</a> &nbsp;&nbsp;
+<a href="./list?page={{voters_page.previous_page_number}}&limit={{limit}}&q={{q|urlencode}}">previous {{limit}}</a> &nbsp;&nbsp;
 {% endif %}
 
 Voters {{voters_page.start_index}} - {{voters_page.end_index}} (of {{total_voters}})&nbsp;&nbsp;
 
 {% if voters_page.has_next %}
-<a href="./list?page={{voters_page.next_page_number}}&limit={{limit}}">next {{limit}}</a> &nbsp;&nbsp;
+<a href="./list?page={{voters_page.next_page_number}}&limit={{limit}}&q={{q|urlencode}}">next {{limit}}</a> &nbsp;&nbsp;
 {% endif %}
 
 <table class="pretty">
@@ -99,7 +103,7 @@ Voters {{voters_page.start_index}} - {{voters_page.end_index}} (of {{total_voter
 </table>
 
 {% else %}
-<em>no voters yet</em>
+<em>no voters.</em>
 {% endif %}
 
 {% endblock %}
diff --git a/helios/views.py b/helios/views.py
index e15f560..35fc415 100644
--- a/helios/views.py
+++ b/helios/views.py
@@ -838,6 +838,7 @@ def voters_list_pretty(request, election):
   # for django pagination support
   page = int(request.GET.get('page', 1))
   limit = int(request.GET.get('limit', 50))
+  q = request.GET.get('q','')
   
   order_by = 'voter_id'
 
@@ -849,6 +850,13 @@ def voters_list_pretty(request, election):
 
   # load a bunch of voters
   voters = Voter.get_by_election(election, order_by=order_by)
+
+  if q != '':
+    if election.use_voter_aliases:
+      voters = voters.filter(alias__icontains = q)
+    else:
+      voters = voters.filter(name__icontains = q)
+
   total_voters = voters.count()
 
   voter_paginator = Paginator(voters, limit)
@@ -858,7 +866,7 @@ def voters_list_pretty(request, election):
                                                   'voters': voters_page.object_list, 'admin_p': admin_p, 
                                                   'email_voters': helios.VOTERS_EMAIL,
                                                   'limit': limit, 'total_voters': total_voters,
-                                                  'upload_p': helios.VOTERS_UPLOAD,
+                                                  'upload_p': helios.VOTERS_UPLOAD, 'q' : q,
                                                   'voter_files': voter_files})
 
 @election_admin(frozen=False)
-- 
GitLab