1 class ElectionsController < ApplicationController
2 model :raw_voter_list, :voter, :vote, :candidate
4 ## general methods for dealing with elections
5 ####################################################################
8 render :action => 'list'
12 @election_pages, @elections = paginate :elections, :per_page => 10
15 ## methods for displaying, creating,
16 ## and manipulating election overview data
17 ####################################################################
20 @election = Election.find(params[:id])
24 @election = Election.new
28 @election = Election.find(params[:id])
32 @election = Election.new(params[:election])
34 flash[:notice] = 'Election was successfully created.'
35 redirect_to :action => 'new_candidates', :id => @election.id
37 render :action => 'new'
42 @election = Election.find(params[:id])
43 if @election.update_attributes(params[:election])
44 flash[:notice] = 'Election was successfully updated.'
45 redirect_to :action => 'show', :id => @election
47 render :action => 'edit'
52 election = Election.find(params[:id]).destroy
53 redirect_to :action => 'list'
56 # methods fod display, adding, deleting, and manipulating candidate
57 # information for elections
58 ####################################################################
60 @election = Election.find( params[:id] )
64 election = Election.find( params[:id] )
65 @candidate = Candidate.new
66 @candidate.name = params[:newcandidate]
68 election.candidates << @candidate
69 render :partial => 'candidate_line'
73 candidate = Candidate.find( params[:id] )
78 @election = Election.find( params[:id] )
81 ## methods for displaying, adding, deleting, and manipulating voters
82 ## for a particular election
83 ####################################################################
85 @election = Election.find( params[:id] )
86 if params.has_key?[:raw_voter_list]
87 process_incoming_voters( params[:raw_voter_list] )
89 @raw_voter_list = RawVoterList.new
94 @election = Election.find( params[:id] )
95 if params.has_key?( :raw_voter_list )
96 process_incoming_voters( params[:raw_voter_list] )
99 @raw_voter_list = RawVoterList.new
103 voter = Voter.find( params[:id] )
107 ## methods for computing and printing results
108 ####################################################################
110 @election = Election.find( params[:id] )
113 @election.voters.each do |voter|
114 if voter.vote and voter.vote.confirmed?
115 votes << voter.vote.rankings.sort.collect {|vote| vote.candidate_id}
119 @voteobj = CloneproofSSDVote.new(votes)
120 @resultobj = @voteobj.result
121 @winners = @resultobj.winners
123 @candidates_by_id = {}
124 @election.candidates.each {|cand| @candidates_by_id[cand.id] = cand}
133 @election.voters. each do |voter|
134 if voter.vote and voter.vote.confirmed?
135 @voter_list << voter.email
136 @vote_list << voter.vote
141 @vote_list.sort! { |a,b| a.token <=> b.token }
145 ####################################################################
148 def process_incoming_voters(raw_voter_list)
149 incoming_voters = RawVoterList.new( raw_voter_list )
151 unless incoming_voters.entries.empty?
152 incoming_voters.each do |new_voter|
154 if incoming_voters.email == 0
155 new_voter.contacted = 1
156 elsif incoming_voters.email == 1
157 email_voter( new_voter )
158 new_voter.contacted = 1
160 new_voter.contacted = 0
163 # the new voter should be in good shape. save add to the election
165 @election.voters << new_voter
169 # reset the next time to have a the same default value for emailing
170 @raw_voter_list = RawVoterList.new
171 @raw_voter_list.email = incoming_voters.email