| @@ -72,6 +72,15 @@ get '/' do | |||||
| # Postcode is valid and in LB Sutton | # Postcode is valid and in LB Sutton | ||||
| @ward = Ward.get(@p.ward_id) | @ward = Ward.get(@p.ward_id) | ||||
| flash[:notice] = "Postcode <strong>#{@postcode}</strong> is in #{@ward.name} ward" | flash[:notice] = "Postcode <strong>#{@postcode}</strong> is in #{@ward.name} ward" | ||||
| if @p.polling_station | |||||
| @ps_postcode = Postcode.get(@p.polling_station.postcode) | |||||
| flash[:polling_station] = "Your polling station is \ | |||||
| <a href=\"http://www.openstreetmap.org/?mlat=%s&mlon=%s&zoom=16\">%s, %s, %s</a>" \ | |||||
| % [ @ps_postcode.lat, @ps_postcode.lng, @p.polling_station.name, \ | |||||
| @p.polling_station.address, @p.polling_station.postcode] | |||||
| end | |||||
| redirect "/bodies/sutton-council/wards/#{@ward.slug}" | redirect "/bodies/sutton-council/wards/#{@ward.slug}" | ||||
| else | else | ||||
| flash.now[:error] = "<strong>#{@postcode}</strong> is not a postcode in Sutton" | flash.now[:error] = "<strong>#{@postcode}</strong> is not a postcode in Sutton" | ||||
| @@ -17,6 +17,21 @@ class Poll | |||||
| belongs_to :district | belongs_to :district | ||||
| end | end | ||||
| class PollingStation | |||||
| include DataMapper::Resource | |||||
| property :id, String, :key => true, :length => 2 # e.g. "KA" | |||||
| property :name, String, :length => 255#, :required => true | |||||
| property :address, String, :length => 255#, :required => true | |||||
| property :postcode, String#, :required => true | |||||
| property :easting, Float, :required => true | |||||
| property :northing, Float, :required => true | |||||
| property :lat, Float, :required => true | |||||
| property :lng, Float, :required => true | |||||
| has n, :postcodes | |||||
| end | |||||
| class Postcode | class Postcode | ||||
| include DataMapper::Resource | include DataMapper::Resource | ||||
| @@ -36,8 +51,10 @@ class Postcode | |||||
| property :lng, Float, :required => true | property :lng, Float, :required => true | ||||
| property :ward_id, Integer, :required => true # Sutton Council | property :ward_id, Integer, :required => true # Sutton Council | ||||
| property :constituency_id, Integer, :required => false # UK Parliament | property :constituency_id, Integer, :required => false # UK Parliament | ||||
| property :polling_station_id, String, :length => 2 | |||||
| belongs_to :district, :child_key => [:ward_id] | belongs_to :district, :child_key => [:ward_id] | ||||
| belongs_to :polling_station | |||||
| def self.finder(postcode) | def self.finder(postcode) | ||||
| postcode = postcode.strip.upcase | postcode = postcode.strip.upcase | ||||
| @@ -289,3 +289,9 @@ tr | |||||
| float: left; | float: left; | ||||
| margin: 0 15px 15px 0; | margin: 0 15px 15px 0; | ||||
| } | } | ||||
| #polling_station { | |||||
| background-color: beige; | |||||
| border: 1px solid green; | |||||
| padding: 20px 20px; | |||||
| } | |||||
| @@ -1,3 +1,13 @@ | |||||
| - if flash[:polling_station] | |||||
| %p | |||||
| #polling_station | |||||
| %h2 Where to vote | |||||
| %p | |||||
| = flash[:polling_station] | |||||
| %p Polling stations are open from 7AM to 10PM on Thursday 22 May 2014. | |||||
| %p You don't need your poll card to vote. Just tell the staff your name and address. | |||||
| - @page_title = "#{@district.name} #{@district.body.district_name}, #{@district.body.name}" | - @page_title = "#{@district.name} #{@district.body.district_name}, #{@district.body.name}" | ||||
| .nav | .nav | ||||