diff --git a/models.rb b/models.rb index d4025e6..a3c084e 100644 --- a/models.rb +++ b/models.rb @@ -74,7 +74,6 @@ class Candidacy property :address, String, :length => 200 property :postcode, String property :position, Integer - property :elected, Boolean property :seats, Integer belongs_to :election @@ -141,10 +140,7 @@ class Party property :name, String, :required => true property :colour, String - has n, :candidates, :order => ['surname'] - - has n, :councilcandidates, :order => ['surname'] - has n, :parliamentcandidates, :order => ['surname'] + has n, :candidacies end # These models are now redundant diff --git a/scripts/setpositions.rb b/scripts/setpositions.rb index 1ca9610..dc91c3a 100644 --- a/scripts/setpositions.rb +++ b/scripts/setpositions.rb @@ -1,4 +1,4 @@ -require './lib/models' +require_relative '../models' require 'pp' # Set position and elected for each candidacy @@ -10,10 +10,10 @@ Election.all.each do |election| puts pos = 1 cands.each do |cand| - pos <= district.seats ? elected = true : elected = false - print cand.candidate.surname, ' ', cand.votes, ' ', pos, ' ', elected, "\n" + pos <= district.seats ? seats = 1 : seats = 0 + print cand.candidate.surname, ' ', cand.votes, ' ', pos, ' ', seats, "\n" cand.position = pos - cand.elected = elected + cand.seats = seats cand.save pos += 1 end diff --git a/views/candidate.haml b/views/candidate.haml index c1e135d..df42df2 100644 --- a/views/candidate.haml +++ b/views/candidate.haml @@ -33,7 +33,7 @@ = ccy.district.body.district_name %td.right= commify(ccy.votes) %td.right= to_ordinal(ccy.position) - %td= ccy.elected? ? "Elected" : "Not elected" + %td= ccy.seats == 1 ? "Elected" : "Not elected" .warning This might not be the complete electoral history for this candidate. They might have stood in elections outside Sutton and / or in Sutton elections for which we don't have data. \ No newline at end of file diff --git a/views/district.haml b/views/district.haml index de5e98c..543102d 100644 --- a/views/district.haml +++ b/views/district.haml @@ -14,7 +14,7 @@ %h2 Candidates elected - Election.all(:body => @district.body, :order => [:d.desc]).each do |election| - - ccys = Candidacy.all(:election_id => election.id, :district_id => @district.id, :elected => true, :order => [:votes.desc]) + - ccys = Candidacy.all(:election_id => election.id, :district_id => @district.id, :seats => 1, :order => [:votes.desc]) - unless ccys == [] %h3