From 4d7a7053a6f9fee5aa3537becb83cbd9500b2115 Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Fri, 7 May 2010 14:09:22 +0100 Subject: [PATCH] Added council election results pages --- app.rb | 7 +++++ lib/models.rb | 3 +- views/resultssuttoncouncil.haml | 49 +++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 views/resultssuttoncouncil.haml diff --git a/app.rb b/app.rb index 173ec42..80acdd6 100644 --- a/app.rb +++ b/app.rb @@ -54,6 +54,13 @@ get '/results/uk-parliament/2010-05-06/:constituency' do haml :resultsukparliament end +get '/results/sutton-council/2010-05-06/:slug' do + @ward = Ward.first(:slug => params[:slug]) + @candidates = Councilcandidate.all(:ward => @ward, :order => [ :votes_2010.desc ]) + @total_2010 = Councilcandidate.sum(:votes_2010, :ward_id => @ward.id) + haml :resultssuttoncouncil +end + get '/how-the-council-election-works' do haml :election end diff --git a/lib/models.rb b/lib/models.rb index 4d878f7..7be3a6d 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -84,7 +84,8 @@ class Councilcandidate property :surname, String, :required => true property :address, String, :length => 200 property :postcode, String, :required => true - + property :votes_2010, Integer + belongs_to :party belongs_to :ward end diff --git a/views/resultssuttoncouncil.haml b/views/resultssuttoncouncil.haml new file mode 100644 index 0000000..fbd767c --- /dev/null +++ b/views/resultssuttoncouncil.haml @@ -0,0 +1,49 @@ +.grid_12 + + %p Sutton Council Election 6 May 2010 Results + + %h1= @ward.name + " Ward" + + - @page_title = @ward.name + " Ward Results, Sutton Council Election 6 May 2010" + + - count = 0 + + %table + %tr + %th + %th + %th.right Votes + -# + %th.right % + %th.right Change + - for candidate in @candidates + - count += 1 + %tr.vcard + %td= count + + %td + %span.candidate_name.fn + = candidate.forenames.split(' ')[0] + = candidate.surname + %br + %span.candidate_party.org + = candidate.party.name + + %td.right= candidate.votes_2010 + + %td.right + - pc_2010 = candidate.votes_2010.to_f / @total_2010 * 100 + = sprintf("%0.1f%%", pc_2010) + -# + %td.right + - unless candidate.percent_2005.nil? + - change_2010 = pc_2010 - candidate.percent_2005 + = sprintf("%+0.1f%%", change_2010) + + %td + - if count < 4 + %strong ELECTED + + %p + Total votes: + = @total_2010