Pārlūkot izejas kodu

Added parliamentary candidates. Text and style changes

tags/last-sinatra-version
Adrian Short pirms 14 gadiem
vecāks
revīzija
ab294690e2
8 mainītis faili ar 106 papildinājumiem un 60 dzēšanām
  1. +6
    -3
      app.rb
  2. +53
    -34
      import.rb
  3. +17
    -0
      lib/models.rb
  4. +2
    -0
      public/style.css
  5. +10
    -5
      views/about.haml
  6. +4
    -1
      views/home.haml
  7. +1
    -0
      views/layout.haml
  8. +13
    -17
      views/wards.haml

+ 6
- 3
app.rb Parādīt failu

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



+ 53
- 34
import.rb Parādīt failu

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


+ 17
- 0
lib/models.rb Parādīt failu

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

+ 2
- 0
public/style.css Parādīt failu

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


+ 10
- 5
views/about.haml Parādīt failu

@@ -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" }<follow me on Twitter
\.
%p It is independent of Sutton Council, all political parties and candidates.
%p This site is independent of Sutton Council, all political parties and candidates. It exists only to provide information about the voting system and local candidates.

%p
The code for this website is open source and managed on Github. It is hosted by Heroku.

The council candidates' data comes from Sutton Council who also provided information on council wards and parliamentary constituencies.
%p
The candidates' data comes from Sutton Council who also provided information on council wards and parliamentary constituencies.
The code for this website is open source and managed on Github. It is hosted by Heroku.
%p
The postcode lookup is done by UK Postcodes using open data from Ordnance Survey Code-Point Open enhanced by MySociety. I use the Ruby Pat gem to access the postcodes API.


+ 4
- 1
views/home.haml Parādīt failu

@@ -1,4 +1,7 @@
%h1 One day. Two elections in Sutton.
%h1
Vote for your MP and councillors
%br
in Sutton

%p
On 6 May you can vote to


+ 1
- 0
views/layout.haml Parādīt failu

@@ -1,3 +1,4 @@
!!! XML
!!!
%html
%head


+ 13
- 17
views/wards.haml Parādīt failu

@@ -1,16 +1,5 @@
- if @postcode
%h1
= @postcode
is in
= @ward_name
Ward
-else
%h1
= @ward.name
Ward

%h2
Your candidates for
%h1
Candidates for
= @ward.constituency.name
member of parliament
@@ -19,7 +8,14 @@
%strong
ONE
of these people to become your next MP.

- for candidate in @parly_candidates
%p
%span.candidate_name
= candidate.forenames
= candidate.surname
%br
= candidate.party.name
%p.highlight
This list of candidates may be incomplete as people have until
@@ -29,8 +25,8 @@
= @ward.constituency.name
MP.
%h2
Your council candidates in
%h1
Council candidates in
= @ward.name
Ward

@@ -44,7 +40,7 @@
Find out more about
%a{ :href => '/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


Notiek ielāde…
Atcelt
Saglabāt