Election results in the London Borough of Sutton.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

app.rb 2.3 KiB

il y a 14 ans
il y a 14 ans
il y a 14 ans
il y a 14 ans
il y a 14 ans
il y a 14 ans
il y a 14 ans
il y a 14 ans
il y a 14 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. require 'rubygems'
  2. require 'sinatra'
  3. require 'sinatra-helpers/haml/partials'
  4. require 'haml'
  5. require 'lib/models'
  6. get '/' do
  7. if params[:postcode]
  8. @postcode = params[:postcode].strip.upcase
  9. unless result = Postcode.finder(@postcode)
  10. # Invalid postcode
  11. redirect '/error'
  12. end
  13. # Postcode valid but not in LB Sutton
  14. if result.district_code != "00BF"
  15. redirect '/aliens'
  16. end
  17. # Postcode in LB Sutton
  18. @ward = Ward.first( :ons_id => result.ward_code )
  19. redirect "/wards/#{@ward.slug}/postcode/#{@postcode}"
  20. end
  21. @wards = Ward.all
  22. @results = repository(:default).adapter.query("
  23. SELECT p.name,
  24. sum(c.votes_2010) AS votes
  25. FROM parties p,
  26. councilcandidates c
  27. WHERE p.id = c.party_id
  28. GROUP BY p.name
  29. ORDER BY votes desc
  30. ;")
  31. select p.name, count(c.*) AS seats
  32. FROM parties p, councilcandidates c
  33. GROUP BY p.id
  34. @total_votes = Councilcandidate.sum(:votes_2010)
  35. haml :home
  36. end
  37. get '/wards/:slug/postcode/:postcode/?' do
  38. @ward = Ward.first(:slug => params[:slug])
  39. @postcode = params[:postcode]
  40. haml :wards
  41. end
  42. get '/wards/:slug/?' do
  43. @ward = Ward.first(:slug => params[:slug])
  44. haml :wards
  45. end
  46. get '/wards/?' do
  47. @wards = Ward.all
  48. haml :wardlist
  49. end
  50. get '/results/uk-parliament/2010-05-06/:constituency' do
  51. if params[:constituency] == 'carshalton-and-wallington'
  52. const = 1
  53. else
  54. const = 2
  55. end
  56. @constituency = Constituency.get(const)
  57. @candidates = Parliamentcandidate.all(:constituency_id => const, :order => [ :votes_2010.desc ])
  58. @total_2010 = Parliamentcandidate.sum(:votes_2010, :constituency_id => const)
  59. haml :resultsukparliament
  60. end
  61. get '/results/sutton-council/2010-05-06/:slug' do
  62. @ward = Ward.first(:slug => params[:slug])
  63. @candidates = Councilcandidate.all(:ward_id => @ward.id, :order => [ :votes_2010.desc ])
  64. @total_2010 = Councilcandidate.sum(:votes_2010, :ward_id => @ward.id)
  65. haml :resultssuttoncouncil
  66. end
  67. get '/how-the-council-election-works' do
  68. haml :election
  69. end
  70. get '/how-the-parliament-election-works' do
  71. haml :parliament
  72. end
  73. # get '/voting' do
  74. # haml :voting
  75. # end
  76. get '/error' do
  77. haml :error
  78. end
  79. get '/about' do
  80. haml :about
  81. end
  82. get '/aliens' do
  83. haml :aliens
  84. end
  85. not_found do
  86. haml :not_found
  87. end