소스 검색

Add turnouts to election summaries and district results

tags/last-sinatra-version
Adrian Short 10 년 전
부모
커밋
daab5c189a
4개의 변경된 파일36개의 추가작업 그리고 2개의 파일을 삭제
  1. +2
    -1
      app.rb
  2. +8
    -0
      models.rb
  3. +13
    -1
      views/electionsummary.haml
  4. +13
    -0
      views/resultsdistrict.haml

+ 2
- 1
app.rb 파일 보기

@@ -241,7 +241,8 @@ get '/bodies/:body/elections/:date/:districts_name/:district' do
@total_candidates = Candidacy.count(:district => @district, :election => @election)
@total_seats = Candidacy.sum(:seats, :district => @district, :election => @election)
@districts_in_this_election = @election.candidacies.districts
@poll = Poll.get(@district.id, @election.id)

# Postgres: All the columns selected when using GROUP BY must either be aggregate functions or appear in the GROUP BY clause
@results_by_party = repository(:default).adapter.select("
SELECT


+ 8
- 0
models.rb 파일 보기

@@ -149,6 +149,14 @@ class Election
self.all(:d.gte => Time.now.to_s, :order => [ :d.desc ])
end
# electorate and ballot_papers_issued assume there's a Poll object for every district in this election
def electorate
Poll.sum(:electorate, :election => self)
end

def ballot_papers_issued
Poll.sum(:ballot_papers_issued, :election => self)
end
end

class District


+ 13
- 1
views/electionsummary.haml 파일 보기

@@ -39,7 +39,7 @@
- unless @election_held
.warning
We don't have the results for this election yet.
%p= @election.reason

%p
@@ -107,6 +107,18 @@
%td  
%td  
%td  

- if @election.ballot_papers_issued
%table
%tr
%td Electorate
%td.right= commify(@election.electorate)
%tr
%td Ballot papers issued
%td.right= commify(@election.ballot_papers_issued)
%tr
%td Turnout
%td.right= sprintf("%.0f%%", @election.ballot_papers_issued / @election.electorate.to_f * 100)
%h2
= @election.body.district_name.capitalize.pluralize(2)


+ 13
- 0
views/resultsdistrict.haml 파일 보기

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

- if @poll
%table
%tr
%td Ballot papers issued
%td.right= commify(@poll.ballot_papers_issued)
%tr
%td Electorate
%td.right= commify(@poll.electorate)
%tr
%td Turnout
%td.right= sprintf("%.0f%%", @poll.turnout_percent)

%h2 Votes by party

%table
@@ -128,3 +140,4 @@
%td.right= commify(@total_votes)
%td  
%td  


불러오는 중...
취소
저장