@@ -10,13 +10,13 @@ DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlit | |||||
DataMapper.auto_upgrade! | DataMapper.auto_upgrade! | ||||
get '/' do | get '/' do | ||||
@wards = Ward.all | |||||
@wards = Ward.all( :order => 'name' ) | |||||
haml :home | haml :home | ||||
end | end | ||||
get '/wards/:id' do | get '/wards/:id' do | ||||
@ward = Ward.get(params[:id]) | @ward = Ward.get(params[:id]) | ||||
@candidates = Councilcandidate.all( :ward_id => @ward.id ) | |||||
@candidates = Councilcandidate.all( :ward_id => @ward.id, :order => 'surname' ) | |||||
haml :wards | haml :wards | ||||
end | end | ||||
@@ -26,7 +26,7 @@ get '/wards' do | |||||
@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 ) | @ward = Ward.first( :name => @ward_name ) | ||||
@candidates = Councilcandidate.all( :ward_id => @ward.id ) | |||||
@candidates = Councilcandidate.all( :ward_id => @ward.id, :order => 'surname') | |||||
haml :wards | haml :wards | ||||
end | end | ||||
@@ -2,22 +2,22 @@ class Postcode | |||||
include DataMapper::Resource | include DataMapper::Resource | ||||
property :id, Serial | 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 | |||||
property :postcode, String, :required => true | |||||
property :created_at, DateTime, :required => true | |||||
property :lat, Float, :required => true | |||||
property :lng, Float, :required => true | |||||
property :district_name, String, :required => true | |||||
property :district_code, String, :required => true | |||||
property :ward_name, String, :required => true | |||||
property :ward_code, String, :required => true | |||||
end | end | ||||
class Ward | class Ward | ||||
include DataMapper::Resource | include DataMapper::Resource | ||||
property :id, Serial | property :id, Serial | ||||
property :ons_id, String, :required => true | |||||
property :name, String, :required => true | |||||
property :ons_id, String, :required => true | |||||
property :name, String, :required => true | |||||
has n, :councilcandidates | has n, :councilcandidates | ||||
end | end | ||||
@@ -26,7 +26,7 @@ class Party | |||||
include DataMapper::Resource | include DataMapper::Resource | ||||
property :id, Serial | property :id, Serial | ||||
property :name, String, :required => true | |||||
property :name, String, :required => true | |||||
has n, :councilcandidates | has n, :councilcandidates | ||||
end | end | ||||
@@ -35,14 +35,13 @@ class Councilcandidate | |||||
include DataMapper::Resource | include DataMapper::Resource | ||||
property :id, Serial | property :id, Serial | ||||
property :ward_id, Integer, :required => true | |||||
property :party_id, Integer, :required => true | |||||
property :forenames, String | |||||
property :surname, String | |||||
property :address, String, :length => 200 | |||||
property :postcode, String | |||||
property :ward_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, :required => true | |||||
belongs_to :party | belongs_to :party | ||||
belongs_to :ward | belongs_to :ward | ||||
end | end |
@@ -6,13 +6,17 @@ | |||||
%p It is independent of Sutton Council, all political parties and candidates. | %p It is independent of Sutton Council, all political parties and candidates. | ||||
%p The code for this website is open source and managed on Github. It is hosted by Heroku. | |||||
%p | |||||
The code for this website is open source and managed on Github. It is hosted by Heroku. | |||||
%p | %p | ||||
The candidates' data comes from Sutton Council. | The candidates' data comes from Sutton Council. | ||||
%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. | |||||
%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. | |||||
%p This site is written in Ruby using the Sinatra framework. The HTML templates use Haml. The database is sqlite for development and postgresql for production, abstracted through DataMapper. Source control and deployment is done with Git. | |||||
%p | |||||
This site is written in Ruby using the Sinatra framework. The HTML templates use Haml. The database is sqlite for development and postgresql for production, abstracted through DataMapper. Source control and deployment is done with Git. | |||||
%h2 #followfooter | %h2 #followfooter | ||||
@@ -2,7 +2,7 @@ | |||||
%p On 6 May 2010 you get to choose your local councillors and to decide who runs Sutton Council for the next four years. | %p On 6 May 2010 you get to choose your local councillors and to decide who runs Sutton Council for the next four years. | ||||
%p The borough is divided into 18 areas called wards. | |||||
%p Sutton borough is divided into 18 areas called wards. | |||||
%p Each ward has three councillors. That makes 54 councillors for the whole borough. | %p Each ward has three councillors. That makes 54 councillors for the whole borough. | ||||
@@ -10,7 +10,7 @@ | |||||
%p The three people with the most votes in each ward become the councillors for that ward. | %p The three people with the most votes in each ward become the councillors for that ward. | ||||
%p If a political party gets 28 or more councillors they get to run the council and decide its policies and services until the next election in four years time. | |||||
%p If a political party gets 28 or more councillors they get to run Sutton Council and decide its policies and services until the next election in four years time. | |||||
%h2 Registering to vote | %h2 Registering to vote | ||||
@@ -1,16 +1,17 @@ | |||||
%h2 One day. Two elections in Sutton. | |||||
-# %h2 One day. Two elections in Sutton. | |||||
%h2 | |||||
Who are my local candidates in the Sutton Council elections on 6 May? | |||||
%h2 Who are my local candidates in the Sutton Council elections on 6 May? | |||||
%form{ :method => 'get', :action => '/wards' } | %form{ :method => 'get', :action => '/wards' } | ||||
%label{ :for => "postcode" } My postcode is | %label{ :for => "postcode" } My postcode is | ||||
%input{ :type => 'text', :name => 'postcode', :value => 'SM1 1EA', :size => 8, :maxlength => 8 } | %input{ :type => 'text', :name => 'postcode', :value => 'SM1 1EA', :size => 8, :maxlength => 8 } | ||||
%input{ :type => 'submit', :value => "Find it" } | %input{ :type => 'submit', :value => "Find it" } | ||||
%h2 Council Wards | |||||
- for ward in @wards | |||||
%p | |||||
%a{ :href => "/wards/#{ward.id.to_s}" } | |||||
= ward.name | |||||
-# | |||||
%h2 Council Wards | |||||
- for ward in @wards | |||||
%p | |||||
%a{ :href => "/wards/#{ward.id.to_s}" } | |||||
= ward.name |
@@ -1,21 +1,21 @@ | |||||
!!! Strict | |||||
!!! | |||||
%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 | |||||
#header | |||||
%a.date{ :href => '/' } 6 MAY 2010 | |||||
#main | |||||
= yield | |||||
#footer | |||||
%body | |||||
#header | |||||
%a.date{ :href => '/' } 6 May 2010 | |||||
#main | |||||
= yield | |||||
#footer | |||||
%p | |||||
%a{ :href => '/how-the-election-works' } How the council election works | |||||
-# | |||||
%p | %p | ||||
%a{ :href => '/how-the-election-works' } How the council election works | |||||
-# | |||||
%p | |||||
%a{ :href => '/voting' } How to vote | |||||
%p | |||||
%a{ :href => '/about' } About this website | |||||
%p.credit | |||||
Design | |||||
%a{ :href => "http://adrianshort.co.uk/" } Adrian Short | |||||
%a{ :href => '/voting' } How to vote | |||||
%p | |||||
%a{ :href => '/about' } About this website | |||||
%p.credit | |||||
Design | |||||
%a{ :href => "http://adrianshort.co.uk/" } Adrian Short |
@@ -1,25 +1,23 @@ | |||||
%h1 | |||||
= @ward.name | |||||
Ward | |||||
- if @postcode | - if @postcode | ||||
%h2 | |||||
%h1 | |||||
= @postcode | = @postcode | ||||
is in | is in | ||||
%span.highlight | |||||
= @ward_name | |||||
Ward | |||||
in | |||||
= @district_name | |||||
%h2 | |||||
Council candidates in | |||||
= @ward.name | |||||
- for candidate in @candidates | |||||
%p | |||||
%span.candidate_name | |||||
= candidate.forenames | |||||
= candidate.surname | |||||
%br | |||||
= candidate.party.name | |||||
= @ward_name | |||||
Ward | |||||
-else | |||||
%h1 | |||||
= @ward.name | |||||
Ward | |||||
#candidates | |||||
%h2 | |||||
Council candidates in | |||||
= @ward.name | |||||
- for candidate in @candidates | |||||
%p | |||||
%span.candidate_name | |||||
= candidate.forenames | |||||
= candidate.surname | |||||
%br | |||||
= candidate.party.name |