Election results in the London Borough of Sutton.
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

108 líneas
2.2 KiB

  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.id
  29. ORDER BY votes desc
  30. ;")
  31. @total_votes = Councilcandidate.sum(:votes_2010)
  32. haml :home
  33. end
  34. get '/wards/:slug/postcode/:postcode/?' do
  35. @ward = Ward.first(:slug => params[:slug])
  36. @postcode = params[:postcode]
  37. haml :wards
  38. end
  39. get '/wards/:slug/?' do
  40. @ward = Ward.first(:slug => params[:slug])
  41. haml :wards
  42. end
  43. get '/wards/?' do
  44. @wards = Ward.all
  45. haml :wardlist
  46. end
  47. get '/results/uk-parliament/2010-05-06/:constituency' do
  48. if params[:constituency] == 'carshalton-and-wallington'
  49. const = 1
  50. else
  51. const = 2
  52. end
  53. @constituency = Constituency.get(const)
  54. @candidates = Parliamentcandidate.all(:constituency_id => const, :order => [ :votes_2010.desc ])
  55. @total_2010 = Parliamentcandidate.sum(:votes_2010, :constituency_id => const)
  56. haml :resultsukparliament
  57. end
  58. get '/results/sutton-council/2010-05-06/:slug' do
  59. @ward = Ward.first(:slug => params[:slug])
  60. @candidates = Councilcandidate.all(:ward_id => @ward.id, :order => [ :votes_2010.desc ])
  61. @total_2010 = Councilcandidate.sum(:votes_2010, :ward_id => @ward.id)
  62. haml :resultssuttoncouncil
  63. end
  64. get '/how-the-council-election-works' do
  65. haml :election
  66. end
  67. get '/how-the-parliament-election-works' do
  68. haml :parliament
  69. end
  70. # get '/voting' do
  71. # haml :voting
  72. # end
  73. get '/error' do
  74. haml :error
  75. end
  76. get '/about' do
  77. haml :about
  78. end
  79. get '/aliens' do
  80. haml :aliens
  81. end
  82. not_found do
  83. haml :not_found
  84. end