#136: Fixed missing polls in projector view
This commit is contained in:
parent
5f3c6c4821
commit
61d4d1ca2f
@ -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)
|
||||
|
@ -4,7 +4,7 @@
|
||||
{% load i18n %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block title %}{{ block.super }} - #{{ item.title }}{% endblock %}
|
||||
{% block title %}{{ block.super }} - {{ item.title }}{% endblock %}
|
||||
{% block header %}
|
||||
<link type="text/css" rel="stylesheet" media="all" href="{% static 'styles/assignment.css' %}" />
|
||||
<script type="text/javascript" src="{% static 'javascript/assignment.js' %}"></script>
|
||||
@ -90,7 +90,7 @@
|
||||
<td>{%trans 'Invalid votes' %}</td>
|
||||
{% for p in polls %}
|
||||
{% if p.published %}
|
||||
<td style="white-space:nowrap;"><img src="{% static 'images/icons/voting-invalid.png' %}" title="{% trans 'Invalid' %}"> {{ p.votesinvalidf }}</td>
|
||||
<td style="white-space:nowrap;"><img src="{% static 'images/icons/voting-invalid.png' %}" title="{% trans 'Invalid' %}"> {{ p.print_votesinvalid }}</td>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tr>
|
||||
@ -98,7 +98,7 @@
|
||||
<td><b>{%trans 'Votes cast' %}</b></td>
|
||||
{% for p in polls %}
|
||||
{% if p.published %}
|
||||
<td style="white-space:nowrap;"><img src="{% static 'images/icons/voting-total.png' %}" title="{% trans 'Votes cast' %}"> <b>{{ p.votescastf }}</b></td>
|
||||
<td style="white-space:nowrap;"><img src="{% static 'images/icons/voting-total.png' %}" title="{% trans 'Votes cast' %}"> <b>{{ p.print_votescast }}</b></td>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tr>
|
||||
|
Loading…
Reference in New Issue
Block a user