| @@ -144,37 +144,18 @@ get '/bodies/:body/elections/:date' do | |||
| ORDER BY seatz DESC, votez DESC | |||
| ", @election.id) | |||
| @results_by_district = repository(:default).adapter.select(" | |||
| SELECT | |||
| d.name, | |||
| d.slug AS district_slug, | |||
| SUM(c.seats) AS seats, | |||
| SUM(c.votes) AS votez, | |||
| COUNT(c.id) AS num_candidates | |||
| FROM districts d, candidacies c | |||
| WHERE | |||
| c.district_id = d.id | |||
| AND c.election_id = ? | |||
| GROUP BY c.district_id, d.name, d.slug | |||
| ORDER BY d.name | |||
| ", @election.id) | |||
| # For elections that haven't yet been held | |||
| @districts_in_this_election = repository(:default).adapter.select(" | |||
| SELECT DISTINCT d.name, d.slug | |||
| FROM candidacies c | |||
| LEFT JOIN districts d | |||
| ON c.district_id = d.id | |||
| WHERE c.election_id = ? | |||
| ORDER BY d.name | |||
| ", @election.id) | |||
| # @districts_in_this_election = repository(:default).adapter.select(" | |||
| # SELECT DISTINCT d.name, d.slug | |||
| # | |||
| # FROM candidacies c | |||
| # LEFT JOIN districts d | |||
| # ON c.district_id = d.id | |||
| # | |||
| # WHERE c.election_id = ? | |||
| # | |||
| # ORDER BY d.name | |||
| # ", @election.id) | |||
| haml :electionsummary | |||
| end | |||
| @@ -31,6 +31,10 @@ class Poll | |||
| def valid_ballot_papers | |||
| self.total_rejected_ballots ? @ballot_papers_issued - self.total_rejected_ballots : nil | |||
| end | |||
| def successful_candidacies # Candidacies where the candidate was elected | |||
| Candidacy.all(:election => @election, :district => @district, :order => [:position], :limit => @seats) | |||
| end | |||
| belongs_to :election | |||
| belongs_to :district | |||
| @@ -119,6 +123,10 @@ class Candidate | |||
| def name | |||
| @forenames + ' ' + @surname | |||
| end | |||
| def url | |||
| "/candidates/" + @id.to_s | |||
| end | |||
| end | |||
| class DeletedCandidate | |||
| @@ -119,37 +119,18 @@ | |||
| %tr | |||
| %td Turnout | |||
| %td.right= sprintf("%.0f%%", @election.ballot_papers_issued / @election.electorate.to_f * 100) | |||
| %h2 | |||
| = @election.body.district_name.capitalize.pluralize(2) | |||
| contested in this election | |||
| %table | |||
| %tr.header | |||
| %th | |||
| %th seats | |||
| %th candidates | |||
| %th votes | |||
| - @results_by_district.each do |row| | |||
| %tr | |||
| %td | |||
| %a{ :href => "/bodies/#{@election.body.slug}/elections/#{@election.d}/#{@election.body.districts_name}/#{row.district_slug}"} | |||
| = row.name | |||
| %td.right= row.seats | |||
| %td.right= row.num_candidates | |||
| %td.right= commify(row.votez) | |||
| %tr.footer | |||
| %td | |||
| %td.right= @total_seats | |||
| %td.right= @election.candidacies.count | |||
| %td.right= commify(@total_votes) | |||
| - else | |||
| %h2 | |||
| = @election.body.district_name.capitalize.pluralize(2) | |||
| being contested at this election | |||
| = "Candidate".pluralize(@total_seats) | |||
| elected | |||
| %table | |||
| - @districts_in_this_election.each do |d| | |||
| - @election.polls.each do |p| | |||
| %tr | |||
| %td | |||
| %a{ :href => "/bodies/#{@election.body.slug}/#{@election.body.districts_name}/#{d['slug']}"} | |||
| = d['name'] | |||
| %a{ :href => "/bodies/#{@election.body.slug}/elections/#{@election.d}/#{@election.body.districts_name}/#{p.district.slug}"} | |||
| = p.district.name | |||
| - p.successful_candidacies.each do |sc| | |||
| %td{ :style => "background-color: #{sc.party.colour};" } | |||
| -# %a{ :href => sc.candidate.url } | |||
| = sc.candidate.short_name | |||