| @@ -4,29 +4,22 @@ require 'pat' | |||||
| require 'dm-core' | require 'dm-core' | ||||
| require 'dm-validations' | require 'dm-validations' | ||||
| require 'dm-timestamps' | require 'dm-timestamps' | ||||
| require 'lib/models' | |||||
| DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3") | DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3") | ||||
| class Postcode | |||||
| include DataMapper::Resource | |||||
| property :id, Integer, :serial => true | |||||
| property :postcode, String, :required => true | |||||
| property :created_at, DateTime | |||||
| property :lat, Float | |||||
| property :lng, Float | |||||
| property :district_name, String | |||||
| property :district_code, String | |||||
| property :ward_name, String | |||||
| property :ward_code, String | |||||
| end | |||||
| DataMapper.auto_upgrade! | DataMapper.auto_upgrade! | ||||
| get '/' do | get '/' do | ||||
| @wards = Ward.all | |||||
| haml :home | haml :home | ||||
| end | end | ||||
| get '/wards/:id' do | |||||
| @ward = Ward.get(params[:id]) | |||||
| @candidates = Councilcandidate.all( :ward_id => @ward.id ) | |||||
| haml :wards | |||||
| end | |||||
| get '/wards' do | get '/wards' do | ||||
| @postcode = params[:postcode].strip.upcase | @postcode = params[:postcode].strip.upcase | ||||
| result = Pat.get(@postcode) | result = Pat.get(@postcode) | ||||
| @@ -44,6 +37,18 @@ end | |||||
| # end | # end | ||||
| get '/about' do | get '/about' do | ||||
| @accounts = %w{ adrianshort mashthestate openlylocal openelection lbsuttonnews stef stonecothill sutmoblib mysociety pezholio stonecotparking } | |||||
| @accounts = %w{ | |||||
| adrianshort | |||||
| mashthestate | |||||
| openlylocal | |||||
| openelection | |||||
| lbsuttonnews | |||||
| stef | |||||
| stonecothill | |||||
| sutmoblib | |||||
| mysociety | |||||
| pezholio | |||||
| stonecotparking | |||||
| } | |||||
| haml :about | haml :about | ||||
| end | end | ||||
| @@ -0,0 +1,48 @@ | |||||
| class Postcode | |||||
| include DataMapper::Resource | |||||
| property :id, Serial | |||||
| property :postcode, String, :required => true | |||||
| property :created_at, DateTime | |||||
| property :lat, Float | |||||
| property :lng, Float | |||||
| property :district_name, String | |||||
| property :district_code, String | |||||
| property :ward_name, String | |||||
| property :ward_code, String | |||||
| end | |||||
| class Ward | |||||
| include DataMapper::Resource | |||||
| property :id, Serial | |||||
| property :ons_id, String, :required => true | |||||
| property :name, String, :required => true | |||||
| has n, :councilcandidates | |||||
| end | |||||
| class Party | |||||
| include DataMapper::Resource | |||||
| property :id, Serial | |||||
| property :name, String, :required => true | |||||
| has n, :councilcandidates | |||||
| end | |||||
| class Councilcandidate | |||||
| include DataMapper::Resource | |||||
| property :id, Serial | |||||
| property :ward_id, Integer, :required => true | |||||
| property :party_id, Integer, :required => true | |||||
| property :forenames, String | |||||
| property :surname, String | |||||
| property :address, String | |||||
| property :postcode, String | |||||
| belongs_to :party | |||||
| belongs_to :ward | |||||
| end | |||||
| @@ -7,4 +7,10 @@ | |||||
| %label{ :for => "postcode" } My postcode is | %label{ :for => "postcode" } My postcode is | ||||
| %input{ :type => 'text', :name => 'postcode', :value => 'SM1 1EA', :size => 8, :maxlength => 8 } | %input{ :type => 'text', :name => 'postcode', :value => 'SM1 1EA', :size => 8, :maxlength => 8 } | ||||
| %input{ :type => 'submit', :value => "Find it" } | %input{ :type => 'submit', :value => "Find it" } | ||||
| %h2 Council Wards | |||||
| - for ward in @wards | |||||
| %p | |||||
| %a{ :href => "/wards/#{ward.id.to_s}" } | |||||
| = ward.name | |||||
| @@ -1,3 +1,7 @@ | |||||
| %h1 | |||||
| = @ward.name | |||||
| Ward | |||||
| %h2 | %h2 | ||||
| = @postcode | = @postcode | ||||
| is in | is in | ||||
| @@ -5,4 +9,12 @@ | |||||
| = @ward_name | = @ward_name | ||||
| Ward | Ward | ||||
| in | in | ||||
| = @district_name | |||||
| = @district_name | |||||
| %h2 Council Candidates | |||||
| - for candidate in @candidates | |||||
| %p | |||||
| = candidate.forenames | |||||
| = candidate.surname | |||||
| %br | |||||
| = candidate.party.name | |||||