Browse Source

Got the candidates to display on each ward page

tags/last-sinatra-version
Adrian Short 14 years ago
parent
commit
d86a4b18b8
7 changed files with 104 additions and 14 deletions
  1. +2
    -0
      app.rb
  2. +60
    -0
      import.rb
  3. +1
    -1
      lib/models.rb
  4. +6
    -1
      public/style.css
  5. +2
    -2
      views/layout.haml
  6. +15
    -10
      views/wards.haml
  7. +18
    -0
      wards.csv

+ 2
- 0
app.rb View File

@@ -25,6 +25,8 @@ get '/wards' do
result = Pat.get(@postcode) result = Pat.get(@postcode)
@district_name = result['administrative']['district']['title'] @district_name = result['administrative']['district']['title']
@ward_name = result['administrative']['ward']['title'] @ward_name = result['administrative']['ward']['title']
@ward = Ward.first( :name => @ward_name )
@candidates = Councilcandidate.all( :ward_id => @ward.id )
haml :wards haml :wards
end end




+ 60
- 0
import.rb View File

@@ -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

+ 1
- 1
lib/models.rb View File

@@ -39,7 +39,7 @@ class Councilcandidate
property :party_id, Integer, :required => true property :party_id, Integer, :required => true
property :forenames, String property :forenames, String
property :surname, String property :surname, String
property :address, String
property :address, String, :length => 200
property :postcode, String property :postcode, String


belongs_to :party belongs_to :party


+ 6
- 1
public/style.css View File

@@ -65,7 +65,7 @@ form


a.date a.date
{ {
font-size: 620%;
font-size: 600%;
font-weight: bold; font-weight: bold;
padding: 30px 30px; padding: 30px 30px;
} }
@@ -78,4 +78,9 @@ a.date
h1 h1
{ {
margin-top: 50px; margin-top: 50px;
}

.candidate_name
{
font-size: 150%;
} }

+ 2
- 2
views/layout.haml View File

@@ -2,10 +2,10 @@
%html %html
%head %head
%title Sutton Council Elections 2010 %title Sutton Council Elections 2010
%link{ :rel => 'stylesheet', :type => 'text/css', :href => 'style.css' }
%link{ :rel => 'stylesheet', :type => 'text/css', :href => '/style.css' }
%body %body
#header #header
%a.date{ :href => '/' } 6 May 2010
%a.date{ :href => '/' } 6 MAY 2010
#main #main
= yield = yield
#footer #footer


+ 15
- 10
views/wards.haml View File

@@ -2,19 +2,24 @@
= @ward.name = @ward.name
Ward Ward


- if @postcode
%h2
= @postcode
is in
%span.highlight
= @ward_name
Ward
in
= @district_name
%h2 %h2
= @postcode
is in
%span.highlight
= @ward_name
Ward
in
= @district_name
Council candidates in
= @ward.name
%h2 Council Candidates
- for candidate in @candidates - for candidate in @candidates
%p %p
= candidate.forenames
= candidate.surname
%span.candidate_name
= candidate.forenames
= candidate.surname
%br %br
= candidate.party.name = candidate.party.name

+ 18
- 0
wards.csv View File

@@ -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

Loading…
Cancel
Save