diff --git a/app.rb b/app.rb index ddeaba1..d4f8bab 100644 --- a/app.rb +++ b/app.rb @@ -4,29 +4,22 @@ require 'pat' require 'dm-core' require 'dm-validations' require 'dm-timestamps' +require 'lib/models' 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! get '/' do + @wards = Ward.all haml :home end +get '/wards/:id' do + @ward = Ward.get(params[:id]) + @candidates = Councilcandidate.all( :ward_id => @ward.id ) + haml :wards +end + get '/wards' do @postcode = params[:postcode].strip.upcase result = Pat.get(@postcode) @@ -44,6 +37,18 @@ end # end 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 end diff --git a/lib/models.rb b/lib/models.rb new file mode 100644 index 0000000..43a926a --- /dev/null +++ b/lib/models.rb @@ -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 \ No newline at end of file diff --git a/views/home.haml b/views/home.haml index ce6f084..c189d56 100644 --- a/views/home.haml +++ b/views/home.haml @@ -7,4 +7,10 @@ %label{ :for => "postcode" } My postcode is %input{ :type => 'text', :name => 'postcode', :value => 'SM1 1EA', :size => 8, :maxlength => 8 } %input{ :type => 'submit', :value => "Find it" } - \ No newline at end of file + +%h2 Council Wards + +- for ward in @wards + %p + %a{ :href => "/wards/#{ward.id.to_s}" } + = ward.name \ No newline at end of file diff --git a/views/wards.haml b/views/wards.haml index ef97024..32479d3 100644 --- a/views/wards.haml +++ b/views/wards.haml @@ -1,3 +1,7 @@ +%h1 + = @ward.name + Ward + %h2 = @postcode is in @@ -5,4 +9,12 @@ = @ward_name Ward in - = @district_name \ No newline at end of file + = @district_name + +%h2 Council Candidates +- for candidate in @candidates + %p + = candidate.forenames + = candidate.surname + %br + = candidate.party.name \ No newline at end of file