Election results in the London Borough of Sutton.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

69 строки
1.5 KiB

  1. require 'rubygems'
  2. require 'sinatra'
  3. require 'sinatra-helpers/haml/partials'
  4. require 'haml'
  5. require 'pat'
  6. require 'dm-core'
  7. require 'dm-validations'
  8. require 'dm-timestamps'
  9. require 'lib/models'
  10. get '/' do
  11. haml :home
  12. end
  13. get '/wards/:id' do
  14. @ward = Ward.get(params[:id])
  15. @council_candidates = Councilcandidate.all( :ward_id => @ward.id, :order => [ 'surname' ] )
  16. @parly_candidates = Parliamentcandidate.all( :constituency_id => @ward.constituency.id, :order => [ 'surname' ])
  17. haml :wards
  18. end
  19. get '/wards' do
  20. @postcode = params[:postcode].strip.upcase
  21. # Postcode not found/invalid
  22. # Postcode valid but not in LB Sutton
  23. result = Pat.get(@postcode)
  24. if result.code == 404
  25. redirect '/error'
  26. end
  27. @district_name = result['administrative']['district']['title']
  28. if @district_name != "Sutton London Borough Council"
  29. redirect '/aliens'
  30. end
  31. @ward_name = result['administrative']['ward']['title']
  32. @ward = Ward.first( { :name => @ward_name } )
  33. @council_candidates = Councilcandidate.all( :ward_id => @ward.id, :order => [ 'surname' ])
  34. @parly_candidates = Parliamentcandidate.all( :constituency_id => @ward.constituency.id, :order => [ 'surname' ])
  35. haml :wards
  36. end
  37. get '/how-the-council-election-works' do
  38. haml :election
  39. end
  40. get '/how-the-parliament-election-works' do
  41. haml :parliament
  42. end
  43. # get '/voting' do
  44. # haml :voting
  45. # end
  46. get '/error' do
  47. haml :error
  48. end
  49. get '/about' do
  50. haml :about
  51. end
  52. get '/aliens' do
  53. haml :aliens
  54. end