Election results in the London Borough of Sutton.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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