Selaa lähdekoodia

Look up polling station by postcode

tags/last-sinatra-version
Adrian Short 12 vuotta sitten
vanhempi
commit
9fb80cc43a
4 muutettua tiedostoa jossa 42 lisäystä ja 0 poistoa
  1. +9
    -0
      app.rb
  2. +17
    -0
      models.rb
  3. +6
    -0
      public/style.css
  4. +10
    -0
      views/district.haml

+ 9
- 0
app.rb Näytä tiedosto

@@ -72,6 +72,15 @@ get '/' do
# Postcode is valid and in LB Sutton
@ward = Ward.get(@p.ward_id)
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}"
else
flash.now[:error] = "<strong>#{@postcode}</strong> is not a postcode in Sutton"


+ 17
- 0
models.rb Näytä tiedosto

@@ -17,6 +17,21 @@ class Poll
belongs_to :district
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
include DataMapper::Resource

@@ -36,8 +51,10 @@ class Postcode
property :lng, Float, :required => true
property :ward_id, Integer, :required => true # Sutton Council
property :constituency_id, Integer, :required => false # UK Parliament
property :polling_station_id, String, :length => 2

belongs_to :district, :child_key => [:ward_id]
belongs_to :polling_station

def self.finder(postcode)
postcode = postcode.strip.upcase


+ 6
- 0
public/style.css Näytä tiedosto

@@ -289,3 +289,9 @@ tr
float: left;
margin: 0 15px 15px 0;
}

#polling_station {
background-color: beige;
border: 1px solid green;
padding: 20px 20px;
}

+ 10
- 0
views/district.haml Näytä tiedosto

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

.nav


Ladataan…
Peruuta
Tallenna