From 4a3564aed87971b4478861c9a92a728995d2c8cc Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Thu, 20 Oct 2011 22:56:22 +0200 Subject: [PATCH] #48 (election): Added percentage for voting results (view, projector, pdf). --- openslides/poll/models.py | 13 +++++++++++++ openslides/utils/pdf.py | 13 ++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/openslides/poll/models.py b/openslides/poll/models.py index 4013c20d7..0f03c8e86 100644 --- a/openslides/poll/models.py +++ b/openslides/poll/models.py @@ -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' diff --git a/openslides/utils/pdf.py b/openslides/utils/pdf.py index 367a1e849..0b532de3f 100755 --- a/openslides/utils/pdf.py +++ b/openslides/utils/pdf.py @@ -555,13 +555,16 @@ def get_assignment(assignment, story): elected = "* " else: elected = "" - row.append(elected+str(candidate[0][0])) + 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))