First Draft for Assignment PDF with fixed vote_results table.

This commit is contained in:
Norman Jäckel 2012-07-06 15:02:31 +02:00
parent c1e9540699
commit 59e6218a80

View File

@ -352,62 +352,68 @@ class AssignmentPDF(PDFView):
for x in range(0,2*assignment.posts): for x in range(0,2*assignment.posts):
cell2b.append(Paragraph("<seq id='counter'/>.&nbsp; __________________________________________",stylesheet['Signaturefield'])) cell2b.append(Paragraph("<seq id='counter'/>.&nbsp; __________________________________________",stylesheet['Signaturefield']))
cell2b.append(Spacer(0,0.2*cm)) cell2b.append(Spacer(0,0.2*cm))
# vote results
table_votes = [] # Vote results
results = self.get_assignment_votes(assignment)
# Preparing
vote_results = assignment.vote_results
data_votes = []
# Left side
cell3a = [] cell3a = []
cell3a.append(Paragraph("%s:" % (_("Vote results")), stylesheet['Heading4'])) cell3a.append(Paragraph("%s:" % (_("Vote results")), stylesheet['Heading4']))
if len(results) > 0:
if len(results[0]) >= 1: if assignment.poll_set.count() > 1:
cell3a.append(Paragraph("%s %s" % (len(results[0][1]), _("ballots")), stylesheet['Normal'])) cell3a.append(Paragraph("%s %s" % (assignment.poll_set.count(), _("ballots")), stylesheet['Normal']))
if len(results[0][1]) > 0:
data_votes = [] # Add table head row
# add table head row
headrow = [] headrow = []
headrow.append(_("Candidates")) headrow.append(_("Candidates"))
for i in range (0,len(results[0][1])): for poll in assignment.poll_set.all():
headrow.append("%s." %(str(i+1))) if poll.published:
headrow.append("%s." % poll.get_ballot())
data_votes.append(headrow) data_votes.append(headrow)
# add result rows
for candidate in results: # Add result rows
for candidate, poll_list in vote_results.iteritems():
row = [] row = []
if candidate[0][1]: if candidate in assignment.elected.all():
elected = "* " row.append("* %s" % str(candidate).split('(',1)[0])
else: else:
elected = "" row.append(candidate)
c = str(candidate[0][0]).split("(",1) for poll_dict in poll_list:
if len(c) > 1: if poll_dict['published']:
row.append(elected+c[0]+"\n"+"("+c[1]) vote = poll_dict['votes']
else: if vote == None:
row.append(elected+str(candidate[0][0])) row.append(_('was not a \ncandidate'))
for votes in candidate[1]: elif 'Yes' in vote and 'No' in vote and 'Abstain' in vote:
if type(votes) == type(list()): tmp = _("Y")+": "+str(vote['Yes'])+"\n"
tmp = _("Y")+": "+str(votes[0])+"\n" tmp += _("N")+": "+str(vote['No'])+"\n"
tmp += _("N")+": "+str(votes[1])+"\n" tmp += _("A")+": "+str(vote['Abstain'])
tmp += _("A")+": "+str(votes[2])
row.append(tmp) row.append(tmp)
elif 'Votes' in vote:
row.append(str(vote['Votes']))
else: else:
row.append(str(votes)) pass
else:
data_votes.append(row) pass
polls = []
for poll in assignment.poll_set.filter(assignment=assignment):
polls.append(poll)
# votes invalid
row = []
row.append(_("Invalid votes"))
for p in polls:
if p.published:
row.append(p.print_votesinvalid())
data_votes.append(row) data_votes.append(row)
# votes cast # Add votes invalid row
row = [] footrow_one = []
row.append(_("Votes cast")) footrow_one.append(_("Invalid votes"))
for p in polls: for poll in assignment.poll_set.all():
if p.published: if poll.published:
row.append(p.print_votescast()) footrow_one.append(poll.print_votesinvalid())
data_votes.append(row) 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())
data_votes.append(footrow_two)
table_votes=Table(data_votes) table_votes=Table(data_votes)
table_votes.setStyle( TableStyle([ table_votes.setStyle( TableStyle([