#48 (election): Added percentage for voting results (view, projector, pdf).

This commit is contained in:
Emanuel Schuetze 2011-10-20 22:56:22 +02:00
parent 34f76c8c28
commit 4a3564aed8
2 changed files with 21 additions and 5 deletions

View File

@ -53,6 +53,10 @@ class Poll(models.Model):
if self.votesinvalid == -2:
return _('undocumented')
elif self.votesinvalid:
if self.votescast > 0:
percentage = round(float(self.votesinvalid) / float(self.votescast) * 100,1)
invalid = "%s (%s %%)" % (str(self.votesinvalid), str(percentage))
return invalid
return self.votesinvalid
return '0'
@ -144,6 +148,9 @@ class Option(models.Model):
if self.voteyes == -2:
return _('undocumented')
if self.voteyes:
if self.poll.votescast > 0 and self.voteyes > 0:
percentage = round(float(self.voteyes) / float(self.poll.votescast) * 100,1)
return "%s (%s %%)" % (str(self.voteyes), str(percentage))
return self.voteyes
return '0'
@ -154,6 +161,9 @@ class Option(models.Model):
if self.voteno == -2:
return _('undocumented')
if self.voteno:
if self.poll.votescast > 0 and self.voteno > 0:
percentage = round(float(self.voteno) / float(self.poll.votescast) * 100,1)
return "%s (%s %%)" % (str(self.voteno), str(percentage))
return self.voteno
return '0'
@ -164,6 +174,9 @@ class Option(models.Model):
if self.voteundesided == -2:
return _('undocumented')
if self.voteundesided:
if self.poll.votescast > 0 and self.voteundesided > 0:
percentage = round(float(self.voteundesided) / float(self.poll.votescast) * 100,1)
return "%s (%s %%)" % (str(self.voteundesided), str(percentage))
return self.voteundesided
return '0'

View File

@ -555,13 +555,16 @@ def get_assignment(assignment, story):
elected = "* "
else:
elected = ""
c = str(candidate[0][0]).split("(",1)
if len(c) > 1:
row.append(elected+c[0]+"\n"+"("+c[1])
else:
row.append(elected+str(candidate[0][0]))
for votes in candidate[1]:
if type(votes) == type(list()):
tmp = "list"
tmp = _("Yes")+": "+str(votes[0])+"\n"
tmp += _("No")+": "+str(votes[1])+"\n"
tmp += _("Abstention")+": "+str(votes[2])
tmp = _("Y")+": "+str(votes[0])+"\n"
tmp += _("N")+": "+str(votes[1])+"\n"
tmp += _("A")+": "+str(votes[2])
row.append(tmp)
else:
row.append(str(votes))