diff --git a/app.rb b/app.rb index 9759b31..f9272d4 100644 --- a/app.rb +++ b/app.rb @@ -1,5 +1,6 @@ require 'rubygems' require 'sinatra' +require 'haml' require 'pat' require 'dm-core' require 'dm-validations' @@ -13,7 +14,8 @@ end get '/wards/:id' do @ward = Ward.get(params[:id]) - @candidates = Councilcandidate.all( :ward_id => @ward.id, :order => 'surname' ) + @council_candidates = Councilcandidate.all( :ward_id => @ward.id, :order => 'surname' ) + @parly_candidates = Parliamentcandidate.all( :constituency_id => @ward.constituency.id, :order => 'surname') haml :wards end @@ -22,8 +24,9 @@ get '/wards' do result = Pat.get(@postcode) @district_name = result['administrative']['district']['title'] @ward_name = result['administrative']['ward']['title'] - @ward = Ward.first( :name => @ward_name ) - @candidates = Councilcandidate.all( :ward_id => @ward.id, :order => 'surname') + @ward = Ward.first( { :name => @ward_name } ) + @council_candidates = Councilcandidate.all( :ward_id => @ward.id, :order => 'surname') + @parly_candidates = Parliamentcandidate.all( :constituency_id => @ward.constituency.id, :order => 'surname') haml :wards end diff --git a/import.rb b/import.rb index 7a4a831..01f297f 100644 --- a/import.rb +++ b/import.rb @@ -5,51 +5,70 @@ require 'dm-validations' require 'dm-timestamps' require 'lib/models' -DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3") -DataMapper.auto_upgrade! - # Import wards +# +# CSV::Reader.parse(File.open('wards.csv', 'rb')) do |row| +# p row +# Ward.create( +# 'ons_id' => row[0], +# 'name' => row[1] +# ) +# end +# +# Define parties -CSV::Reader.parse(File.open('wards.csv', 'rb')) do |row| - p row - Ward.create( - 'ons_id' => row[0], - 'name' => row[1] - ) -end +# parties = [ +# "British National Party", +# "Christian Peoples Alliance", +# "Conservative Party", +# "Green Party", +# "Labour Party", +# "Labour and Co-Operative Party", +# "Liberal Democrats", +# "United Kingdom Independence Party", +# "Libertarian Party" +# ] +# +# for party in parties +# puts party +# Party.create( :name => party ) +# end -# Define parties +# Import council candidates -parties = [ - "British National Party", - "Christian Peoples Alliance", - "Conservative Party", - "Green Party", - "Labour Party", - "Labour and Co-Operative Party", - "Liberal Democrats", - "United Kingdom Independence Party" -] - -for party in parties - puts party - Party.create( :name => party ) -end +# CSV::Reader.parse(File.open('../candidates-pretty.csv', 'rb')) do |row| +# p row +# +# c = Councilcandidate.new( +# 'forenames' => row[1], +# 'surname' => row[2], +# 'address' => row[4], +# 'postcode' => row[5] +# ) +# +# c.ward = Ward.first( :name => row[0] ) +# c.party = Party.first( :name => row[3] ) +# +# unless c.save +# puts "ERROR: Failed to save candidate" +# c.errors.each do |e| +# puts e +# end +# end +# end -# Import candidates +# Import parliament candidates -CSV::Reader.parse(File.open('../candidates-pretty.csv', 'rb')) do |row| +CSV::Reader.parse(File.open('../parliament-candidates.csv', 'rb')) do |row| p row - c = Councilcandidate.new( + c = Parliamentcandidate.new( 'forenames' => row[1], - 'surname' => row[2], - 'address' => row[4], - 'postcode' => row[5] + 'surname' => row[2] ) - c.ward = Ward.first( :name => row[0] ) - c.party = Party.first( :name => row[3] ) + c.constituency = Constituency.first( :name => row[3] ) + c.party = Party.first( :name => row[0] ) unless c.save puts "ERROR: Failed to save candidate" diff --git a/lib/models.rb b/lib/models.rb index d837a74..a22b221 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -31,6 +31,7 @@ class Party property :name, String, :required => true has n, :councilcandidates + has n, :parliamentcandidates end class Councilcandidate @@ -48,6 +49,21 @@ class Councilcandidate belongs_to :ward end +class Parliamentcandidate + include DataMapper::Resource + + property :id, Serial + property :constituency_id, Integer, :required => true + property :party_id, Integer, :required => true + property :forenames, String, :required => true + property :surname, String, :required => true + property :address, String, :length => 200 + property :postcode, String + + belongs_to :party + belongs_to :constituency +end + class Constituency include DataMapper::Resource @@ -55,6 +71,7 @@ class Constituency property :name, String, :required => true has n, :wards + has n, :parliamentcandidates end DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3") diff --git a/public/style.css b/public/style.css index 34ea4bd..22a3e87 100644 --- a/public/style.css +++ b/public/style.css @@ -56,6 +56,7 @@ a:hover h2 { margin-top: 50px; + line-height: 1.5em; } form @@ -78,6 +79,7 @@ a.date h1 { margin-top: 50px; + line-height: 1.5em; } .candidate_name diff --git a/views/about.haml b/views/about.haml index dcddbe8..856a268 100644 --- a/views/about.haml +++ b/views/about.haml @@ -2,15 +2,20 @@ %p This website was designed by - %a{ :href => 'http://adrianshort.co.uk' } Adrian Short + %a{ :href => 'http://adrianshort.co.uk' }> Adrian Short + \. + You can contact me by email at + %a{ :href => "mailto:adrian.short@gmail.com" }< adrian.short@gmail.com + and + %a{ :href => "http://twitter.com/adrianshort" } '/how-the-council-election-works' } how the council election works. -- for candidate in @candidates +- for candidate in @council_candidates %p %span.candidate_name = candidate.forenames