diff --git a/app.rb b/app.rb index 689d962..e5df2ce 100644 --- a/app.rb +++ b/app.rb @@ -10,13 +10,13 @@ DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlit DataMapper.auto_upgrade! get '/' do - @wards = Ward.all + @wards = Ward.all( :order => 'name' ) haml :home end get '/wards/:id' do @ward = Ward.get(params[:id]) - @candidates = Councilcandidate.all( :ward_id => @ward.id ) + @candidates = Councilcandidate.all( :ward_id => @ward.id, :order => 'surname' ) haml :wards end @@ -26,7 +26,7 @@ get '/wards' do @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 ) + @candidates = Councilcandidate.all( :ward_id => @ward.id, :order => 'surname') haml :wards end diff --git a/lib/models.rb b/lib/models.rb index 2ef2fcc..fde3b5a 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -2,22 +2,22 @@ class Postcode include DataMapper::Resource 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 class Ward include DataMapper::Resource 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 end @@ -26,7 +26,7 @@ class Party include DataMapper::Resource property :id, Serial - property :name, String, :required => true + property :name, String, :required => true has n, :councilcandidates end @@ -35,14 +35,13 @@ class Councilcandidate include DataMapper::Resource 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 :ward - end \ No newline at end of file diff --git a/views/about.haml b/views/about.haml index 6e0468a..df11176 100644 --- a/views/about.haml +++ b/views/about.haml @@ -6,13 +6,17 @@ %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 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 diff --git a/views/election.haml b/views/election.haml index 6bbabcf..f329b17 100644 --- a/views/election.haml +++ b/views/election.haml @@ -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 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. @@ -10,7 +10,7 @@ %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 diff --git a/views/home.haml b/views/home.haml index c189d56..c272e93 100644 --- a/views/home.haml +++ b/views/home.haml @@ -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' } %label{ :for => "postcode" } My postcode is %input{ :type => 'text', :name => 'postcode', :value => 'SM1 1EA', :size => 8, :maxlength => 8 } %input{ :type => 'submit', :value => "Find it" } -%h2 Council Wards - -- for ward in @wards - %p - %a{ :href => "/wards/#{ward.id.to_s}" } - = ward.name \ No newline at end of file +-# + + %h2 Council Wards + + - for ward in @wards + %p + %a{ :href => "/wards/#{ward.id.to_s}" } + = ward.name \ No newline at end of file diff --git a/views/layout.haml b/views/layout.haml index d405cfb..bab10ef 100644 --- a/views/layout.haml +++ b/views/layout.haml @@ -1,21 +1,21 @@ -!!! Strict +!!! %html %head %title Sutton Council Elections 2010 %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 - %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 \ No newline at end of file + %a{ :href => '/voting' } How to vote + %p + %a{ :href => '/about' } About this website + %p.credit + Design + %a{ :href => "http://adrianshort.co.uk/" } Adrian Short \ No newline at end of file diff --git a/views/wards.haml b/views/wards.haml index ed8adb8..c1b7b34 100644 --- a/views/wards.haml +++ b/views/wards.haml @@ -1,25 +1,23 @@ -%h1 - = @ward.name - Ward - - if @postcode - %h2 + %h1 = @postcode 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 \ No newline at end of file + = @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 \ No newline at end of file