diff --git a/app.rb b/app.rb index d4f8bab..689d962 100644 --- a/app.rb +++ b/app.rb @@ -25,6 +25,8 @@ 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 ) haml :wards end diff --git a/import.rb b/import.rb new file mode 100644 index 0000000..7a4a831 --- /dev/null +++ b/import.rb @@ -0,0 +1,60 @@ +require 'rubygems' +require 'csv' +require 'dm-core' +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 + +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 + +# Import candidates + +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 diff --git a/lib/models.rb b/lib/models.rb index 43a926a..2ef2fcc 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -39,7 +39,7 @@ class Councilcandidate property :party_id, Integer, :required => true property :forenames, String property :surname, String - property :address, String + property :address, String, :length => 200 property :postcode, String belongs_to :party diff --git a/public/style.css b/public/style.css index 79767c4..84c08ee 100644 --- a/public/style.css +++ b/public/style.css @@ -65,7 +65,7 @@ form a.date { - font-size: 620%; + font-size: 600%; font-weight: bold; padding: 30px 30px; } @@ -78,4 +78,9 @@ a.date h1 { margin-top: 50px; +} + +.candidate_name +{ + font-size: 150%; } \ No newline at end of file diff --git a/views/layout.haml b/views/layout.haml index 00437b3..d405cfb 100644 --- a/views/layout.haml +++ b/views/layout.haml @@ -2,10 +2,10 @@ %html %head %title Sutton Council Elections 2010 - %link{ :rel => 'stylesheet', :type => 'text/css', :href => 'style.css' } + %link{ :rel => 'stylesheet', :type => 'text/css', :href => '/style.css' } %body #header - %a.date{ :href => '/' } 6 May 2010 + %a.date{ :href => '/' } 6 MAY 2010 #main = yield #footer diff --git a/views/wards.haml b/views/wards.haml index 32479d3..ed8adb8 100644 --- a/views/wards.haml +++ b/views/wards.haml @@ -2,19 +2,24 @@ = @ward.name Ward +- if @postcode + %h2 + = @postcode + is in + %span.highlight + = @ward_name + Ward + in + = @district_name + %h2 - = @postcode - is in - %span.highlight - = @ward_name - Ward - in - = @district_name + Council candidates in + = @ward.name -%h2 Council Candidates - for candidate in @candidates %p - = candidate.forenames - = candidate.surname + %span.candidate_name + = candidate.forenames + = candidate.surname %br = candidate.party.name \ No newline at end of file diff --git a/wards.csv b/wards.csv new file mode 100644 index 0000000..b3cb154 --- /dev/null +++ b/wards.csv @@ -0,0 +1,18 @@ +00BFGC,Beddington North +00BFGD,Beddington South +00BFGE,Belmont +00BFGF,Carshalton Central +00BFGG,Carshalton South and Clockhouse +00BFGH,Cheam +00BFGJ,Nonsuch +00BFGK,St Helier +00BFGL,Stonecot +00BFGM,Sutton Central +00BFGN,Sutton North +00BFGP,Sutton South +00BFGQ,Sutton West +00BFGR,The Wrythe +00BFGS,Wallington North +00BFGT,Wallington South +00BFGU,Wandle Valley +00BFGW,Worcester Park \ No newline at end of file