diff --git a/app.rb b/app.rb
index 06d3350..72721e2 100644
--- a/app.rb
+++ b/app.rb
@@ -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 #{@postcode} 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 #{@postcode} 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 \
%s, %s, %s" \
% [ @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] = "#{@postcode} is not a postcode in Sutton"
end
diff --git a/views/district.haml b/views/district.haml
index 9d479e4..8cb271b 100644
--- a/views/district.haml
+++ b/views/district.haml
@@ -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
diff --git a/views/electionsummary.haml b/views/electionsummary.haml
index 513c825..d7007fc 100644
--- a/views/electionsummary.haml
+++ b/views/electionsummary.haml
@@ -40,6 +40,9 @@
.warning
We don't have the results for this election yet.
+%p= @polling_station
+
+
%p= @election.reason
%p
diff --git a/views/index.haml b/views/index.haml
index 10b7736..4ece92c 100644
--- a/views/index.haml
+++ b/views/index.haml
@@ -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 }