Browse Source

Tidy up postcode lookup

tags/last-sinatra-version
Adrian Short 9 years ago
parent
commit
c941ae6e95
4 changed files with 19 additions and 11 deletions
  1. +14
    -7
      app.rb
  2. +1
    -3
      views/district.haml
  3. +3
    -0
      views/electionsummary.haml
  4. +1
    -1
      views/index.haml

+ 14
- 7
app.rb View File

@@ -65,23 +65,30 @@ helpers do
end

get '/' do
@election = Election.get(9) # FIXME magic number
@election_title = "#{@election.body.name} #{@election.kind} #{long_date(@election.d)}"
if params[:postcode]
@postcode = params[:postcode].strip.upcase

if @p = Postcode.get(@postcode)
if @p = Postcode.get(params[:postcode].strip.upcase)
# 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 @election.body.district_name == 'constituency'
@district = District.get(@p.constituency_id)
else
@district = District.get(@p.ward_id)
end
flash[:notice] = "Postcode <strong>#{@postcode}</strong> is in #{@district.name} #{@election.body.district_name}"

if @p.polling_station
@ps_postcode = Postcode.get(@p.polling_station.postcode)
flash[:polling_station] = "Your polling station is \
@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/elections/2014-05-22/wards/#{@ward.slug}"
redirect "/bodies/#{@election.body.slug}/elections/#{@election.d}/#{@election.body.districts_name}/#{@district.slug}"
else
flash.now[:error] = "<strong>#{@postcode}</strong> is not a postcode in Sutton"
end


+ 1
- 3
views/district.haml View File

@@ -8,9 +8,7 @@

%h1= "#{@district.name} #{@district.body.district_name}"

-# Candidates for 22 May 2014 council election

- @election = Election.get(8)
- @election = Election.get(9) # FIXME magic number

%h2
= @district.name


+ 3
- 0
views/electionsummary.haml View File

@@ -40,6 +40,9 @@
.warning
We don't have the results for this election yet.

%p= @polling_station


%p= @election.reason

%p


+ 1
- 1
views/index.haml View File

@@ -2,7 +2,7 @@

#lookup
%h2
Sutton Council local election results 22 May 2014
= @election_title
%form{ :method => 'get', :action => '/' }
%label{ :for => "postcode" } My postcode is
%input{ :type => 'text', :name => 'postcode', :value => @default_pc, :size => 8, :maxlength => 8 }


Loading…
Cancel
Save