From 61d4d1ca2fb03747e8f1021a243394cf873fca3e Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Sat, 21 Apr 2012 21:38:59 +0200 Subject: [PATCH] #136: Fixed missing polls in projector view --- openslides/assignment/models.py | 41 ++++++++++++++++++- .../templates/projector/Assignment.html | 6 +-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py index 02f38ba7c..3be2d7570 100644 --- a/openslides/assignment/models.py +++ b/openslides/assignment/models.py @@ -12,6 +12,8 @@ from django.db import models +from config.models import config + from participant.models import Profile from projector.projector import SlideMixin @@ -19,6 +21,7 @@ from projector.api import register_slidemodel from poll.models import BasePoll, CountInvalid, CountVotesCast, BaseOption, PublishPollMixin from utils.translation_ext import ugettext as _ + class Assignment(models.Model, SlideMixin): prefix = 'assignment' STATUS = ( @@ -90,9 +93,42 @@ class Assignment(models.Model, SlideMixin): def gen_poll(self): poll = AssignmentPoll(assignment=self) poll.save() - poll.set_options([{'candidate': profile} for profile in self.profile.all()]) + candidates = list(self.profile.all()) + for elected in self.elected.all(): + try: + candidates.remove(elected) + except ValueError: + pass + poll.set_options([{'candidate': profile} for profile in candidates]) return poll + @property + def vote_results(self): + votes = [] + publish_winner_results_only = config["assignment_publish_winner_results_only"] + # list of votes + votes = [] + for candidate in self.candidates: + tmplist = [[candidate, self.is_elected(candidate)], []] + for poll in self.poll_set.all(): + if poll.published: + if poll.get_options().filter(candidate=candidate).exists(): + # check config option 'publish_winner_results_only' + if not publish_winner_results_only \ + or publish_winner_results_only and self.is_elected(candidate): + option = AssignmentOption.objects.filter(poll=poll).get(candidate=candidate) + try: + tmplist[1].append(option.get_votes()[0]) + except IndexError: + tmplist[1].append('–') + else: + tmplist[1].append("") + else: + tmplist[1].append("-") + votes.append(tmplist) + return votes + + def slide(self): """ return the slide dict @@ -100,6 +136,8 @@ class Assignment(models.Model, SlideMixin): data = super(Assignment, self).slide() data['assignment'] = self data['title'] = self.name + data['polls'] = self.poll_set.all() + data['votes'] = self.vote_results data['template'] = 'projector/Assignment.html' return data @@ -163,4 +201,5 @@ def default_config(sender, key, **kwargs): return { 'assignment_pdf_ballot_papers_selection': '1', 'assignment_pdf_title': _('Elections'), + 'assignment_publish_winner_results_only': False, }.get(key) diff --git a/openslides/assignment/templates/projector/Assignment.html b/openslides/assignment/templates/projector/Assignment.html index 6fea3d7d3..1c434b0b3 100644 --- a/openslides/assignment/templates/projector/Assignment.html +++ b/openslides/assignment/templates/projector/Assignment.html @@ -4,7 +4,7 @@ {% load i18n %} {% load staticfiles %} -{% block title %}{{ block.super }} - #{{ item.title }}{% endblock %} +{% block title %}{{ block.super }} - {{ item.title }}{% endblock %} {% block header %} @@ -90,7 +90,7 @@ {%trans 'Invalid votes' %} {% for p in polls %} {% if p.published %} - {{ p.votesinvalidf }} + {{ p.print_votesinvalid }} {% endif %} {% endfor %} @@ -98,7 +98,7 @@ {%trans 'Votes cast' %} {% for p in polls %} {% if p.published %} - {{ p.votescastf }} + {{ p.print_votescast }} {% endif %} {% endfor %}