diff --git a/openslides/assignments/static/js/assignments/base.js b/openslides/assignments/static/js/assignments/base.js index cd1a35c5c..e3928c054 100644 --- a/openslides/assignments/static/js/assignments/base.js +++ b/openslides/assignments/static/js/assignments/base.js @@ -42,7 +42,7 @@ angular.module('OpenSlidesApp.assignments', []) } else if (config == "WITH_INVALID" && poll.votescast > 0 && vote.weight >= 0) { percentNumber = Math.round(vote.weight * 100 / (poll.votescast) * 10) / 10; } - if (percentNumber >=0 ) { + if (percentNumber >= 0 ) { percentStr = "(" + percentNumber + "%)"; } votes.push({ diff --git a/openslides/assignments/views.py b/openslides/assignments/views.py index d7ca68ef6..7ea979bed 100644 --- a/openslides/assignments/views.py +++ b/openslides/assignments/views.py @@ -510,7 +510,7 @@ class AssignmentPollPDF(PDFView): 'yes': _("Yes"), 'no': _("No"), 'abstain': _("Abstain")}, - stylesheet['Ballot_option_circle_YNA'])) + stylesheet['Ballot_option_circle_YNA'])) else: cell.append(Paragraph( " ", stylesheet['Ballot_option_suffix_YNA'])) diff --git a/openslides/motions/config_variables.py b/openslides/motions/config_variables.py index 18d1ac59c..f71902cda 100644 --- a/openslides/motions/config_variables.py +++ b/openslides/motions/config_variables.py @@ -1,4 +1,5 @@ from django.core.validators import MinValueValidator +from django.utils.translation import ugettext_lazy from openslides.core.config import ConfigVariable from openslides.poll.models import PERCENT_BASE_CHOICES @@ -23,6 +24,10 @@ def get_config_variables(): papers' and 'PDF'. The generator has to be evaluated during app loading (see apps.py). """ + percent_base_choices_motion = PERCENT_BASE_CHOICES + percent_base_choices_motion += ({ + 'value': "WITHOUT_ABSTAIN", + 'display_name': ugettext_lazy('Yes and No votes')},) # General yield ConfigVariable( name='motions_workflow', @@ -148,7 +153,7 @@ def get_config_variables(): default_value='WITHOUT_INVALID', input_type='choice', label='The 100 % base of a voting result consists of', - choices=PERCENT_BASE_CHOICES, + choices=percent_base_choices_motion, weight=355, group='Motions', subgroup='Voting and ballot papers') diff --git a/openslides/motions/static/js/motions/base.js b/openslides/motions/static/js/motions/base.js index 3e374a653..cf94e940c 100644 --- a/openslides/motions/static/js/motions/base.js +++ b/openslides/motions/static/js/motions/base.js @@ -71,7 +71,7 @@ angular.module('OpenSlidesApp.motions', [ }, methods: { // returns object with value and percent - getVote: function (vote) { + getVote: function (vote, type) { if (!this.has_votes) { return; } @@ -89,13 +89,18 @@ angular.module('OpenSlidesApp.motions', [ } // calculate percent value var config = Config.get('motions_poll_100_percent_base').value; - var percentStr, percentNumber; + var percentStr; + var percentNumber = null; if (config == "WITHOUT_INVALID" && this.votesvalid > 0 && vote >= 0) { percentNumber = Math.round(vote * 100 / this.votesvalid * 10) / 10; } else if (config == "WITH_INVALID" && this.votescast > 0 && vote >= 0) { percentNumber = Math.round(vote * 100 / (this.votescast) * 10) / 10; + } else if (config == "WITHOUT_ABSTAIN" && this.votesvalid > 0 && vote >= 0){ + if (type == 'yes' || type == 'no') { + percentNumber = Math.round(vote * 100 / (this.yes + this.no) * 10) / 10; + } } - if (percentNumber) { + if (percentNumber !== null) { percentStr = "(" + percentNumber + "%)"; } return { @@ -103,7 +108,7 @@ angular.module('OpenSlidesApp.motions', [ 'percentStr': percentStr, 'percentNumber': percentNumber }; - }, + } } }); } diff --git a/openslides/motions/static/js/motions/site.js b/openslides/motions/static/js/motions/site.js index fa67c4d0a..24f40883e 100644 --- a/openslides/motions/static/js/motions/site.js +++ b/openslides/motions/static/js/motions/site.js @@ -70,14 +70,15 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions', 'OpenSlid results = function() { return motion.polls.map(function(poll, index) { var id = index + 1, - yes = poll.yes, - yesRelative = (poll.yes) * 100 / (poll.votescast), - no = poll.no, - noRelative = (poll.no) * 100 / (poll.votescast), - abstain = poll.abstain, - abstainRelative = (poll.abstain) * 100 / (poll.votescast), + yes = poll.yes ? poll.yes : 0, // if no poll.yes is given, set it to 0 + yesRelative = poll.getVote(poll.yes, 'yes').percentStr, + no = poll.no ? poll.no : 0, + noRelative = poll.getVote(poll.no, 'no').percentStr, + abstain = poll.abstain ? poll.abstain : 0, + abstainrelativeGet = poll.getVote(poll.abstain, 'abstain').percentStr, + abstainRelative = abstainrelativeGet? abstainrelativeGet : "", valid = poll.votesvalid, - validRelative = (poll.votesvalid) * 100 / (poll.votescast), + validRelative = poll.getVote(poll.votesvalid, 'votesvalid').percentStr, number = { text: id + ".", width: "5%" @@ -100,7 +101,7 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions', 'OpenSlid var indexColumn = converter.createElement("text"); var nameColumn = converter.createElement("text", "" + name); var valueColumn = converter.createElement("text", "" + value); - var relColumn = converter.createElement("text", "(" + "" + relValue + "%)"); + var relColumn = converter.createElement("text", relValue); valueColumn.width = "40%"; indexColumn.width = "5%"; valueColumn.width = "5%"; diff --git a/openslides/motions/static/templates/motions/motion-detail.html b/openslides/motions/static/templates/motions/motion-detail.html index 2d480d9af..c1e33d77d 100644 --- a/openslides/motions/static/templates/motions/motion-detail.html +++ b/openslides/motions/static/templates/motions/motion-detail.html @@ -151,7 +151,7 @@ - + Yes: {{ voteYes.value }} {{ voteYes.percentStr }} @@ -163,7 +163,7 @@ - + No: {{ voteNo.value }} {{ voteNo.percentStr }} @@ -175,7 +175,7 @@ - + Abstain: {{ voteAbstain.value }} {{ voteAbstain.percentStr }} @@ -187,7 +187,7 @@ - + Valid votes: {{ votesValid.value }} {{ votesValid.percentStr }} @@ -196,7 +196,7 @@ - + Invalid votes: {{ votesInvalid.value }} @@ -208,7 +208,7 @@ - + Votes cast: {{ votesCast.value }} diff --git a/openslides/motions/static/templates/motions/slide_motion.html b/openslides/motions/static/templates/motions/slide_motion.html index 20d73c4cf..d19789357 100644 --- a/openslides/motions/static/templates/motions/slide_motion.html +++ b/openslides/motions/static/templates/motions/slide_motion.html @@ -23,36 +23,36 @@ - + Yes: {{ voteYes.value }} {{ voteYes.percentStr }} -
+
- + No: {{ voteNo.value }} {{ voteNo.percentStr }} -
+
- + Abstain: {{ voteAbstain.value }} {{ voteAbstain.percentStr }} -
+
diff --git a/openslides/poll/models.py b/openslides/poll/models.py index 51bb4db22..e05663af8 100644 --- a/openslides/poll/models.py +++ b/openslides/poll/models.py @@ -66,9 +66,8 @@ class BaseVote(models.Model): percent_base = 0 return print_value(self.weight, percent_base) - PERCENT_BASE_CHOICES = ( - {'value': 'WITHOUT_INVALID', 'display_name': ugettext_lazy('Only all valid votes')}, + {'value': 'WITHOUT_INVALID', 'display_name': ugettext_lazy('All valid votes (Yes/No/Abstain)')}, {'value': 'WITH_INVALID', 'display_name': ugettext_lazy('All votes cast (including invalid votes)')}, {'value': 'DISABLED', 'display_name': ugettext_lazy('Disabled (no percents)')}) @@ -119,9 +118,11 @@ class CollectDefaultVotesMixin(models.Model): return value def get_percent_base(self): - if self.get_percent_base_choice() == "WITHOUT_INVALID" and self.votesvalid and self.votesvalid > 0: + if self.get_percent_base_choice() == "WITHOUT_INVALID" and\ + self.votesvalid and self.votesvalid > 0: base = 100 / float(self.votesvalid) - elif self.get_percent_base_choice() == "WITH_INVALID" and self.votescast and self.votescast > 0: + elif self.get_percent_base_choice() == "WITH_INVALID" and\ + self.votescast and self.votescast > 0: base = 100 / float(self.votescast) else: base = None