From 333349a1f2d62d3defb16102acf2e90125dcebd6 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Tue, 10 Jul 2012 00:47:00 +0200 Subject: [PATCH] Only show voteresult-table where there is at least one published poll. Also fix AssignmentPDF-Poll-Table --- openslides/assignment/models.py | 18 ++- .../assignment/templates/assignment/view.html | 61 ++++----- .../templates/projector/Assignment.html | 46 +++---- openslides/assignment/views.py | 117 ++++++++---------- 4 files changed, 110 insertions(+), 132 deletions(-) diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py index d5d0752d3..177544703 100644 --- a/openslides/assignment/models.py +++ b/openslides/assignment/models.py @@ -108,8 +108,7 @@ class Assignment(models.Model, SlideMixin): return poll - @property - def vote_results(self): + def vote_results(self, only_published): """ returns a table represented as a list with all candidates from all related polls and their vote results. @@ -117,6 +116,8 @@ class Assignment(models.Model, SlideMixin): vote_results_dict = {} # All polls related to this assigment polls = self.poll_set.all() + if only_published: + polls = polls.filter(published=True) # All PollOption-Objects related to this assignment options = [] for poll in polls: @@ -128,18 +129,15 @@ class Assignment(models.Model, SlideMixin): continue vote_results_dict[candidate] = [] for poll in polls: - votes = { - 'votes': {}, - 'published': poll.published, - } + votes = {} try: # candidate related to this poll poll_option = poll.get_options().get(candidate=candidate) for vote in poll_option.get_votes(): - votes['votes'][vote.value] = vote.get_weight() + votes[vote.value] = vote.get_weight() except AssignmentOption.DoesNotExist: # candidate not in related to this poll - votes['votes'] = None + votes = None vote_results_dict[candidate].append(votes) return vote_results_dict @@ -159,8 +157,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['vote_results'] = self.vote_results + data['polls'] = self.poll_set.filter(published=True) + data['vote_results'] = self.vote_results(only_published=True) data['assignment_publish_winner_results_only'] = config['assignment_publish_winner_results_only'] data['template'] = 'projector/Assignment.html' return data diff --git a/openslides/assignment/templates/assignment/view.html b/openslides/assignment/templates/assignment/view.html index 63b1527e1..f138d98ca 100644 --- a/openslides/assignment/templates/assignment/view.html +++ b/openslides/assignment/templates/assignment/view.html @@ -112,21 +112,19 @@ {% trans "Candidates" %} {% for poll in polls %} - {% if poll.published or perms.assignment.can_manage_assignment %} - - {{ forloop.counter }}. {% trans 'ballot' %} - {% if perms.assignment.can_manage_assignment %} -
- - - - - - {% endif %} - - {% endif %} + + {{ poll.get_ballot }}. {% trans 'ballot' %} + {% if perms.assignment.can_manage_assignment %} +
+ + + + + + {% endif %} + {% endfor %} {% if assignment.profile.exists and perms.assignment.can_manage_assignment and assignment.status == "vot" %} @@ -144,7 +142,6 @@ {% if candidate in assignment.elected.all %} {% if perms.assignment.can_manage_assignment %} - {# What does this line do #} {% else %} @@ -158,24 +155,20 @@ {% endif %} {{ candidate }} - {% for poll_dict in poll_list %} - {% if perms.assignment.can_manage_assignment or poll_dict.published %} - {% with vote=poll_dict.votes %} - - {% if 'Yes' in vote and 'No' in vote and 'Abstain' in vote %} - {{ vote.Yes }}
- {{ vote.No }}
- {{ vote.Abstain }}
- {% elif 'Votes' in vote %} - {{ vote.Votes }} - {% elif vote == None %} - {% trans 'was not a
candidate'%} - {% else %} -   - {% endif %} - - {% endwith %} - {% endif %} + {% for vote in poll_list %} + + {% if 'Yes' in vote and 'No' in vote and 'Abstain' in vote %} + {{ vote.Yes }}
+ {{ vote.No }}
+ {{ vote.Abstain }}
+ {% elif 'Votes' in vote %} + {{ vote.Votes }} + {% elif vote == None %} + {% trans 'was not a
candidate'%} + {% else %} +   + {% endif %} + {% endfor %} {% if assignment.profile.exists and perms.assignment.can_manage_assignment and assignment.status == "vot" %} diff --git a/openslides/assignment/templates/projector/Assignment.html b/openslides/assignment/templates/projector/Assignment.html index 43520ce69..7bf00e1ba 100644 --- a/openslides/assignment/templates/projector/Assignment.html +++ b/openslides/assignment/templates/projector/Assignment.html @@ -54,10 +54,8 @@ {% trans "Candidates" %} - {% for poll in assignment.poll_set.all %} - {% if poll.published %} - {{forloop.counter}}. {% trans "ballot" %} - {% endif %} + {% for poll in polls %} + {{ poll.get_ballot }}. {% trans "ballot" %} {% endfor %} @@ -71,28 +69,24 @@ {% endif %} {{ candidate }} - {% for poll_dict in poll_list %} - {% if poll_dict.published %} - {% with vote=poll_dict.votes %} - - {% 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 %} - {{ vote.Yes }}
- {{ vote.No }}
- {{ vote.Abstain }}
- {% elif 'Votes' in vote %} - {{ vote.Votes }} - {% elif vote == None %} - {% trans 'was not a
candidate'%} - {% else %} -   - {% endif %} - {% else %} -   - {% endif %} - - {% endwith %} - {% endif %} + {% for vote in poll_list %} + + {% 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 %} + {{ vote.Yes }}
+ {{ vote.No }}
+ {{ vote.Abstain }}
+ {% elif 'Votes' in vote %} + {{ vote.Votes }} + {% elif vote == None %} + {% trans 'was not a
candidate'%} + {% else %} +   + {% endif %} + {% else %} +   + {% endif %} + {% endfor %} {% endfor %} diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py index ff4759802..983d06fd2 100644 --- a/openslides/assignment/views.py +++ b/openslides/assignment/views.py @@ -84,8 +84,14 @@ def view(request, assignment_id=None): if request.user.has_perm('assignment.can_nominate_other'): form = AssignmentRunForm() - vote_results = assignment.vote_results + 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 { 'assignment': assignment, 'form': form, @@ -328,10 +334,12 @@ class AssignmentPDF(PDFView): # Assignment details (each assignment on single page) for assignment in assignments: 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 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): # title @@ -349,52 +357,56 @@ class AssignmentPDF(PDFView): for c in assignment.profile.all(): cell2b.append(Paragraph(".  %s" % unicode(c), stylesheet['Signaturefield'])) if assignment.status == "sea": - for x in range(0,2*assignment.posts): + for x in range(0, 2 * assignment.posts): cell2b.append(Paragraph(".  __________________________________________",stylesheet['Signaturefield'])) cell2b.append(Spacer(0,0.2*cm)) # Vote results # Preparing - vote_results = assignment.vote_results + vote_results = assignment.vote_results(only_published=True) + polls = assignment.poll_set.filter(published=True) data_votes = [] + # Left side cell3a = [] cell3a.append(Paragraph("%s:" % (_("Vote results")), stylesheet['Heading4'])) - if assignment.poll_set.count() > 1: - cell3a.append(Paragraph("%s %s" % (assignment.poll_set.count(), _("ballots")), stylesheet['Normal'])) + if polls.count() == 1: + 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 headrow = [] headrow.append(_("Candidates")) - for poll in assignment.poll_set.all(): - if poll.published: - headrow.append("%s." % poll.get_ballot()) + for poll in polls: + headrow.append("%s." % poll.get_ballot()) data_votes.append(headrow) + # Add result rows + elected_candidates = assignment.elected.all() for candidate, poll_list in vote_results.iteritems(): row = [] - if candidate in assignment.elected.all(): - row.append("* %s" % str(candidate).split('(',1)[0]) - else: - row.append(str(candidate).split('(',1)[0]) - for poll_dict in poll_list: - if poll_dict['published']: - vote = poll_dict['votes'] - if vote == None: - row.append(_('was not a \ncandidate')) - elif 'Yes' in vote and 'No' in vote and 'Abstain' in vote: - tmp = _("Y")+": "+str(vote['Yes'])+"\n" - tmp += _("N")+": "+str(vote['No'])+"\n" - tmp += _("A")+": "+str(vote['Abstain']) - row.append(tmp) - elif 'Votes' in vote: - row.append(str(vote['Votes'])) - else: - pass + + candidate_string = candidate.user.get_full_name() + if candidate in elected_candidates: + candidate_string = "* " + candidate_string + if candidate.group: + candidate_string += "\n(%s)" % candidate.group + row.append(candidate_string) + for vote in poll_list: + if vote == None: + row.append('–') + elif 'Yes' in vote and 'No' in vote and 'Abstain' in vote: + tmp = _("Y")+": " + vote['Yes'] + "\n" + tmp += _("N")+": " + vote['No'] + "\n" + tmp += _("A")+": " + vote['Abstain'] + row.append(tmp) + elif 'Votes' in vote: + row.append(vote['Votes']) else: pass data_votes.append(row) @@ -402,37 +414,35 @@ class AssignmentPDF(PDFView): # Add votes invalid row footrow_one = [] footrow_one.append(_("Invalid votes")) - for poll in assignment.poll_set.all(): - if poll.published: - footrow_one.append(poll.print_votesinvalid()) + for poll in polls: + footrow_one.append(poll.print_votesinvalid()) data_votes.append(footrow_one) # Add votes cast row footrow_two = [] footrow_two.append(_("Votes cast")) - for poll in assignment.poll_set.all(): - if poll.published: - footrow_two.append(poll.print_votescast()) + for poll in polls: + footrow_two.append(poll.print_votescast()) data_votes.append(footrow_two) table_votes=Table(data_votes) table_votes.setStyle( TableStyle([ - ('GRID', (0,0), (-1,-1), 0.5, colors.grey), - ('VALIGN',(0,0),(-1,-1), 'TOP'), - ('LINEABOVE',(0,0),(-1,0),2,colors.black), - ('LINEABOVE',(0,1),(-1,1),1,colors.black), - ('LINEBELOW',(0,-1),(-1,-1),2,colors.black), - ('ROWBACKGROUNDS', (0, 1), (-1, -1), (colors.white, (.9, .9, .9))), - ])) + ('GRID', (0, 0), (-1, -1), 0.5, colors.grey), + ('VALIGN',(0, 0),(-1, -1), 'TOP'), + ('LINEABOVE',(0, 0),(-1, 0), 2, colors.black), + ('LINEABOVE',(0, 1),(-1, 1), 1, colors.black), + ('LINEBELOW',(0, -1),(-1, -1), 2, colors.black), + ('ROWBACKGROUNDS', (0, 1), (-1, -1), (colors.white, (.9, .9, .9))), + ])) # table data = [] data.append([cell1a,cell1b]) - if table_votes: + if polls: data.append([cell3a,table_votes]) - data.append(['','* = '+_('elected')]) + data.append(['', '* = '+_('elected')]) else: - data.append([cell2a,cell2b]) + data.append([cell2a, cell2b]) data.append([Spacer(0,0.2*cm),'']) t=Table(data) t._argW[0]=4.5*cm @@ -442,26 +452,9 @@ class AssignmentPDF(PDFView): ])) story.append(t) story.append(Spacer(0,1*cm)) + # text story.append(Paragraph("%s" % assignment.description.replace('\r\n','
'), 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):