Only show voteresult-table where there is at least one published poll.
Also fix AssignmentPDF-Poll-Table
This commit is contained in:
parent
cd245e4605
commit
333349a1f2
@ -108,8 +108,7 @@ class Assignment(models.Model, SlideMixin):
|
|||||||
return poll
|
return poll
|
||||||
|
|
||||||
|
|
||||||
@property
|
def vote_results(self, only_published):
|
||||||
def vote_results(self):
|
|
||||||
"""
|
"""
|
||||||
returns a table represented as a list with all candidates from all
|
returns a table represented as a list with all candidates from all
|
||||||
related polls and their vote results.
|
related polls and their vote results.
|
||||||
@ -117,6 +116,8 @@ class Assignment(models.Model, SlideMixin):
|
|||||||
vote_results_dict = {}
|
vote_results_dict = {}
|
||||||
# All polls related to this assigment
|
# All polls related to this assigment
|
||||||
polls = self.poll_set.all()
|
polls = self.poll_set.all()
|
||||||
|
if only_published:
|
||||||
|
polls = polls.filter(published=True)
|
||||||
# All PollOption-Objects related to this assignment
|
# All PollOption-Objects related to this assignment
|
||||||
options = []
|
options = []
|
||||||
for poll in polls:
|
for poll in polls:
|
||||||
@ -128,18 +129,15 @@ class Assignment(models.Model, SlideMixin):
|
|||||||
continue
|
continue
|
||||||
vote_results_dict[candidate] = []
|
vote_results_dict[candidate] = []
|
||||||
for poll in polls:
|
for poll in polls:
|
||||||
votes = {
|
votes = {}
|
||||||
'votes': {},
|
|
||||||
'published': poll.published,
|
|
||||||
}
|
|
||||||
try:
|
try:
|
||||||
# candidate related to this poll
|
# candidate related to this poll
|
||||||
poll_option = poll.get_options().get(candidate=candidate)
|
poll_option = poll.get_options().get(candidate=candidate)
|
||||||
for vote in poll_option.get_votes():
|
for vote in poll_option.get_votes():
|
||||||
votes['votes'][vote.value] = vote.get_weight()
|
votes[vote.value] = vote.get_weight()
|
||||||
except AssignmentOption.DoesNotExist:
|
except AssignmentOption.DoesNotExist:
|
||||||
# candidate not in related to this poll
|
# candidate not in related to this poll
|
||||||
votes['votes'] = None
|
votes = None
|
||||||
vote_results_dict[candidate].append(votes)
|
vote_results_dict[candidate].append(votes)
|
||||||
return vote_results_dict
|
return vote_results_dict
|
||||||
|
|
||||||
@ -159,8 +157,8 @@ class Assignment(models.Model, SlideMixin):
|
|||||||
data = super(Assignment, self).slide()
|
data = super(Assignment, self).slide()
|
||||||
data['assignment'] = self
|
data['assignment'] = self
|
||||||
data['title'] = self.name
|
data['title'] = self.name
|
||||||
data['polls'] = self.poll_set.all()
|
data['polls'] = self.poll_set.filter(published=True)
|
||||||
data['vote_results'] = self.vote_results
|
data['vote_results'] = self.vote_results(only_published=True)
|
||||||
data['assignment_publish_winner_results_only'] = config['assignment_publish_winner_results_only']
|
data['assignment_publish_winner_results_only'] = config['assignment_publish_winner_results_only']
|
||||||
data['template'] = 'projector/Assignment.html'
|
data['template'] = 'projector/Assignment.html'
|
||||||
return data
|
return data
|
||||||
|
@ -112,9 +112,8 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>{% trans "Candidates" %}</th>
|
<th>{% trans "Candidates" %}</th>
|
||||||
{% for poll in polls %}
|
{% for poll in polls %}
|
||||||
{% if poll.published or perms.assignment.can_manage_assignment %}
|
|
||||||
<th style="vertical-align: top; white-space:nowrap;">
|
<th style="vertical-align: top; white-space:nowrap;">
|
||||||
{{ forloop.counter }}. {% trans 'ballot' %}
|
{{ poll.get_ballot }}. {% trans 'ballot' %}
|
||||||
{% if perms.assignment.can_manage_assignment %}
|
{% if perms.assignment.can_manage_assignment %}
|
||||||
<br>
|
<br>
|
||||||
<a class="publish_link {% if poll.published %}published{% endif %}"
|
<a class="publish_link {% if poll.published %}published{% endif %}"
|
||||||
@ -126,7 +125,6 @@
|
|||||||
<a href="{% url assignment_poll_delete poll.id %}"><img src="{% static 'images/icons/delete.png' %}" title="{% trans 'Delete' %}"></a>
|
<a href="{% url assignment_poll_delete poll.id %}"><img src="{% static 'images/icons/delete.png' %}" title="{% trans 'Delete' %}"></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</th>
|
</th>
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if assignment.profile.exists and perms.assignment.can_manage_assignment and assignment.status == "vot" %}
|
{% if assignment.profile.exists and perms.assignment.can_manage_assignment and assignment.status == "vot" %}
|
||||||
<th>
|
<th>
|
||||||
@ -144,7 +142,6 @@
|
|||||||
<td class="candidate">
|
<td class="candidate">
|
||||||
{% if candidate in assignment.elected.all %}
|
{% if candidate in assignment.elected.all %}
|
||||||
{% if perms.assignment.can_manage_assignment %}
|
{% if perms.assignment.can_manage_assignment %}
|
||||||
{# What does this line do #}
|
|
||||||
<a class="election_link elected" href='{% url assignment_user_not_elected assignment.id candidate.id %}'></a>
|
<a class="election_link elected" href='{% url assignment_user_not_elected assignment.id candidate.id %}'></a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a class="elected">
|
<a class="elected">
|
||||||
@ -158,9 +155,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{{ candidate }}
|
{{ candidate }}
|
||||||
</td>
|
</td>
|
||||||
{% for poll_dict in poll_list %}
|
{% for vote in poll_list %}
|
||||||
{% if perms.assignment.can_manage_assignment or poll_dict.published %}
|
|
||||||
{% with vote=poll_dict.votes %}
|
|
||||||
<td style="white-space:nowrap;">
|
<td style="white-space:nowrap;">
|
||||||
{% if 'Yes' in vote and 'No' in vote and 'Abstain' in vote %}
|
{% if 'Yes' in vote and 'No' in vote and 'Abstain' in vote %}
|
||||||
<img src="{% static 'images/icons/voting-yes.png' %}" title="{% trans 'Yes' %}"> {{ vote.Yes }}<br>
|
<img src="{% static 'images/icons/voting-yes.png' %}" title="{% trans 'Yes' %}"> {{ vote.Yes }}<br>
|
||||||
@ -174,8 +169,6 @@
|
|||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
{% endwith %}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if assignment.profile.exists and perms.assignment.can_manage_assignment and assignment.status == "vot" %}
|
{% if assignment.profile.exists and perms.assignment.can_manage_assignment and assignment.status == "vot" %}
|
||||||
<td></td>
|
<td></td>
|
||||||
|
@ -54,10 +54,8 @@
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th>{% trans "Candidates" %}</th>
|
<th>{% trans "Candidates" %}</th>
|
||||||
{% for poll in assignment.poll_set.all %}
|
{% for poll in polls %}
|
||||||
{% if poll.published %}
|
<th><nobr>{{ poll.get_ballot }}. {% trans "ballot" %}</nobr></th>
|
||||||
<th><nobr>{{forloop.counter}}. {% trans "ballot" %}</nobr></th>
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@ -71,9 +69,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{{ candidate }}
|
{{ candidate }}
|
||||||
</td>
|
</td>
|
||||||
{% for poll_dict in poll_list %}
|
{% for vote in poll_list %}
|
||||||
{% if poll_dict.published %}
|
|
||||||
{% with vote=poll_dict.votes %}
|
|
||||||
<td style="white-space:nowrap;"{% if candidate in assignment.elected.all %} class="elected"{% endif %}>
|
<td style="white-space:nowrap;"{% if candidate in assignment.elected.all %} class="elected"{% endif %}>
|
||||||
{% if not assignment_publish_winner_results_only or candidate in assignment.elected.all %}
|
{% if not assignment_publish_winner_results_only or candidate in assignment.elected.all %}
|
||||||
{% if 'Yes' in vote and 'No' in vote and 'Abstain' in vote %}
|
{% if 'Yes' in vote and 'No' in vote and 'Abstain' in vote %}
|
||||||
@ -91,8 +87,6 @@
|
|||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
{% endwith %}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -84,8 +84,14 @@ def view(request, assignment_id=None):
|
|||||||
if request.user.has_perm('assignment.can_nominate_other'):
|
if request.user.has_perm('assignment.can_nominate_other'):
|
||||||
form = AssignmentRunForm()
|
form = AssignmentRunForm()
|
||||||
|
|
||||||
vote_results = assignment.vote_results
|
|
||||||
polls = assignment.poll_set.all()
|
polls = assignment.poll_set.all()
|
||||||
|
if not request.user.has_perm('assignment.can_manage_assignment'):
|
||||||
|
polls = assignment.poll_set.filter(published=True)
|
||||||
|
vote_results = assignment.vote_results(only_published=True)
|
||||||
|
else:
|
||||||
|
polls = assignment.poll_set.all()
|
||||||
|
vote_results = assignment.vote_results(only_published=False)
|
||||||
return {
|
return {
|
||||||
'assignment': assignment,
|
'assignment': assignment,
|
||||||
'form': form,
|
'form': form,
|
||||||
@ -328,10 +334,12 @@ class AssignmentPDF(PDFView):
|
|||||||
# Assignment details (each assignment on single page)
|
# Assignment details (each assignment on single page)
|
||||||
for assignment in assignments:
|
for assignment in assignments:
|
||||||
story.append(PageBreak())
|
story.append(PageBreak())
|
||||||
story = self.get_assignment(assignment, story)
|
# append the assignment to the story-object
|
||||||
|
self.get_assignment(assignment, story)
|
||||||
else: # print selected assignment
|
else: # print selected assignment
|
||||||
assignment = Assignment.objects.get(id=assignment_id)
|
assignment = Assignment.objects.get(id=assignment_id)
|
||||||
story = self.get_assignment(assignment, story)
|
# append the assignment to the story-object
|
||||||
|
self.get_assignment(assignment, story)
|
||||||
|
|
||||||
def get_assignment(self, assignment, story):
|
def get_assignment(self, assignment, story):
|
||||||
# title
|
# title
|
||||||
@ -356,45 +364,49 @@ class AssignmentPDF(PDFView):
|
|||||||
# Vote results
|
# Vote results
|
||||||
|
|
||||||
# Preparing
|
# Preparing
|
||||||
vote_results = assignment.vote_results
|
vote_results = assignment.vote_results(only_published=True)
|
||||||
|
polls = assignment.poll_set.filter(published=True)
|
||||||
data_votes = []
|
data_votes = []
|
||||||
|
|
||||||
|
|
||||||
# Left side
|
# Left side
|
||||||
cell3a = []
|
cell3a = []
|
||||||
cell3a.append(Paragraph("%s:" % (_("Vote results")), stylesheet['Heading4']))
|
cell3a.append(Paragraph("%s:" % (_("Vote results")), stylesheet['Heading4']))
|
||||||
|
|
||||||
if assignment.poll_set.count() > 1:
|
if polls.count() == 1:
|
||||||
cell3a.append(Paragraph("%s %s" % (assignment.poll_set.count(), _("ballots")), stylesheet['Normal']))
|
cell3a.append(Paragraph("%s %s" % (polls.count(), _("ballot")), stylesheet['Normal']))
|
||||||
|
elif polls.count() > 1:
|
||||||
|
cell3a.append(Paragraph("%s %s" % (polls.count(), _("ballots")), stylesheet['Normal']))
|
||||||
|
|
||||||
# Add table head row
|
# Add table head row
|
||||||
headrow = []
|
headrow = []
|
||||||
headrow.append(_("Candidates"))
|
headrow.append(_("Candidates"))
|
||||||
for poll in assignment.poll_set.all():
|
for poll in polls:
|
||||||
if poll.published:
|
|
||||||
headrow.append("%s." % poll.get_ballot())
|
headrow.append("%s." % poll.get_ballot())
|
||||||
data_votes.append(headrow)
|
data_votes.append(headrow)
|
||||||
|
|
||||||
|
|
||||||
# Add result rows
|
# Add result rows
|
||||||
|
elected_candidates = assignment.elected.all()
|
||||||
for candidate, poll_list in vote_results.iteritems():
|
for candidate, poll_list in vote_results.iteritems():
|
||||||
row = []
|
row = []
|
||||||
if candidate in assignment.elected.all():
|
|
||||||
row.append("* %s" % str(candidate).split('(',1)[0])
|
candidate_string = candidate.user.get_full_name()
|
||||||
else:
|
if candidate in elected_candidates:
|
||||||
row.append(str(candidate).split('(',1)[0])
|
candidate_string = "* " + candidate_string
|
||||||
for poll_dict in poll_list:
|
if candidate.group:
|
||||||
if poll_dict['published']:
|
candidate_string += "\n(%s)" % candidate.group
|
||||||
vote = poll_dict['votes']
|
row.append(candidate_string)
|
||||||
|
for vote in poll_list:
|
||||||
if vote == None:
|
if vote == None:
|
||||||
row.append(_('was not a \ncandidate'))
|
row.append('–')
|
||||||
elif 'Yes' in vote and 'No' in vote and 'Abstain' in vote:
|
elif 'Yes' in vote and 'No' in vote and 'Abstain' in vote:
|
||||||
tmp = _("Y")+": "+str(vote['Yes'])+"\n"
|
tmp = _("Y")+": " + vote['Yes'] + "\n"
|
||||||
tmp += _("N")+": "+str(vote['No'])+"\n"
|
tmp += _("N")+": " + vote['No'] + "\n"
|
||||||
tmp += _("A")+": "+str(vote['Abstain'])
|
tmp += _("A")+": " + vote['Abstain']
|
||||||
row.append(tmp)
|
row.append(tmp)
|
||||||
elif 'Votes' in vote:
|
elif 'Votes' in vote:
|
||||||
row.append(str(vote['Votes']))
|
row.append(vote['Votes'])
|
||||||
else:
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
data_votes.append(row)
|
data_votes.append(row)
|
||||||
@ -402,16 +414,14 @@ class AssignmentPDF(PDFView):
|
|||||||
# Add votes invalid row
|
# Add votes invalid row
|
||||||
footrow_one = []
|
footrow_one = []
|
||||||
footrow_one.append(_("Invalid votes"))
|
footrow_one.append(_("Invalid votes"))
|
||||||
for poll in assignment.poll_set.all():
|
for poll in polls:
|
||||||
if poll.published:
|
|
||||||
footrow_one.append(poll.print_votesinvalid())
|
footrow_one.append(poll.print_votesinvalid())
|
||||||
data_votes.append(footrow_one)
|
data_votes.append(footrow_one)
|
||||||
|
|
||||||
# Add votes cast row
|
# Add votes cast row
|
||||||
footrow_two = []
|
footrow_two = []
|
||||||
footrow_two.append(_("Votes cast"))
|
footrow_two.append(_("Votes cast"))
|
||||||
for poll in assignment.poll_set.all():
|
for poll in polls:
|
||||||
if poll.published:
|
|
||||||
footrow_two.append(poll.print_votescast())
|
footrow_two.append(poll.print_votescast())
|
||||||
data_votes.append(footrow_two)
|
data_votes.append(footrow_two)
|
||||||
|
|
||||||
@ -428,7 +438,7 @@ class AssignmentPDF(PDFView):
|
|||||||
# table
|
# table
|
||||||
data = []
|
data = []
|
||||||
data.append([cell1a,cell1b])
|
data.append([cell1a,cell1b])
|
||||||
if table_votes:
|
if polls:
|
||||||
data.append([cell3a,table_votes])
|
data.append([cell3a,table_votes])
|
||||||
data.append(['', '* = '+_('elected')])
|
data.append(['', '* = '+_('elected')])
|
||||||
else:
|
else:
|
||||||
@ -442,26 +452,9 @@ class AssignmentPDF(PDFView):
|
|||||||
]))
|
]))
|
||||||
story.append(t)
|
story.append(t)
|
||||||
story.append(Spacer(0,1*cm))
|
story.append(Spacer(0,1*cm))
|
||||||
|
|
||||||
# text
|
# text
|
||||||
story.append(Paragraph("%s" % assignment.description.replace('\r\n','<br/>'), stylesheet['Paragraph']))
|
story.append(Paragraph("%s" % assignment.description.replace('\r\n','<br/>'), stylesheet['Paragraph']))
|
||||||
return story
|
|
||||||
|
|
||||||
def get_assignment_votes(self, assignment):
|
|
||||||
votes = []
|
|
||||||
for candidate in assignment.candidates:
|
|
||||||
tmplist = ((candidate, assignment.is_elected(candidate)), [])
|
|
||||||
for poll in assignment.poll_set.all():
|
|
||||||
if poll.published:
|
|
||||||
if poll.get_options().filter(candidate=candidate).exists():
|
|
||||||
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("-")
|
|
||||||
votes.append(tmplist)
|
|
||||||
return votes
|
|
||||||
|
|
||||||
|
|
||||||
class CreateAgendaItem(RedirectView):
|
class CreateAgendaItem(RedirectView):
|
||||||
|
Loading…
Reference in New Issue
Block a user