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,72 +352,78 @@ 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 poll in assignment.poll_set.all():
for i in range (0,len(results[0][1])): if poll.published:
headrow.append("%s." %(str(i+1))) headrow.append("%s." % poll.get_ballot())
data_votes.append(headrow) data_votes.append(headrow)
# add result rows
for candidate in results: # Add result rows
row = [] for candidate, poll_list in vote_results.iteritems():
if candidate[0][1]: row = []
elected = "* " if candidate in assignment.elected.all():
row.append("* %s" % str(candidate).split('(',1)[0])
else:
row.append(candidate)
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: else:
elected = "" pass
c = str(candidate[0][0]).split("(",1) else:
if len(c) > 1: pass
row.append(elected+c[0]+"\n"+"("+c[1]) data_votes.append(row)
else:
row.append(elected+str(candidate[0][0]))
for votes in candidate[1]:
if type(votes) == type(list()):
tmp = _("Y")+": "+str(votes[0])+"\n"
tmp += _("N")+": "+str(votes[1])+"\n"
tmp += _("A")+": "+str(votes[2])
row.append(tmp)
else:
row.append(str(votes))
data_votes.append(row) # Add votes invalid row
polls = [] footrow_one = []
for poll in assignment.poll_set.filter(assignment=assignment): footrow_one.append(_("Invalid votes"))
polls.append(poll) for poll in assignment.poll_set.all():
# votes invalid if poll.published:
row = [] footrow_one.append(poll.print_votesinvalid())
row.append(_("Invalid votes")) data_votes.append(footrow_one)
for p in polls:
if p.published:
row.append(p.print_votesinvalid())
data_votes.append(row)
# votes cast # Add votes cast row
row = [] footrow_two = []
row.append(_("Votes cast")) footrow_two.append(_("Votes cast"))
for p in polls: for poll in assignment.poll_set.all():
if p.published: if poll.published:
row.append(p.print_votescast()) footrow_two.append(poll.print_votescast())
data_votes.append(row) data_votes.append(footrow_two)
table_votes=Table(data_votes) table_votes=Table(data_votes)
table_votes.setStyle( TableStyle([ table_votes.setStyle( TableStyle([
('GRID', (0,0), (-1,-1), 0.5, colors.grey), ('GRID', (0,0), (-1,-1), 0.5, colors.grey),
('VALIGN',(0,0),(-1,-1), 'TOP'), ('VALIGN',(0,0),(-1,-1), 'TOP'),
('LINEABOVE',(0,0),(-1,0),2,colors.black), ('LINEABOVE',(0,0),(-1,0),2,colors.black),
('LINEABOVE',(0,1),(-1,1),1,colors.black), ('LINEABOVE',(0,1),(-1,1),1,colors.black),
('LINEBELOW',(0,-1),(-1,-1),2,colors.black), ('LINEBELOW',(0,-1),(-1,-1),2,colors.black),
('ROWBACKGROUNDS', (0, 1), (-1, -1), (colors.white, (.9, .9, .9))), ('ROWBACKGROUNDS', (0, 1), (-1, -1), (colors.white, (.9, .9, .9))),
])) ]))
# table # table
data = [] data = []