Fixed index error while generating assignment pdf.

This commit is contained in:
Emanuel Schuetze 2011-09-11 18:37:20 +02:00
parent 7ef4013b4b
commit 9917e2f545

View File

@ -505,6 +505,8 @@ def get_assignment_votes(assignment):
tmplist[1].append(option.yes) tmplist[1].append(option.yes)
else: else:
tmplist[1].append("-") tmplist[1].append("-")
elif len(tmplist[1]) == 0:
return votes
votes.append(tmplist) votes.append(tmplist)
return votes return votes
@ -532,14 +534,15 @@ def get_assignment(assignment, story):
results = get_assignment_votes(assignment) results = get_assignment_votes(assignment)
cell3a = [] cell3a = []
cell3a.append(Paragraph("%s:" % (_("Vote results")), stylesheet['Heading4'])) cell3a.append(Paragraph("%s:" % (_("Vote results")), stylesheet['Heading4']))
if len(results[1][1]) > 1: if len(results) > 0:
cell3a.append(Paragraph("%s %s" % (len(results[1][1]), _("ballots")), stylesheet['Normal'])) if len(results[0]) >= 1:
if len(results[1][1]) > 0: cell3a.append(Paragraph("%s %s" % (len(results[0][1]), _("ballots")), stylesheet['Normal']))
if len(results[0][1]) > 0:
data_votes = [] 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[1][1])): for i in range (0,len(results[0][1])):
headrow.append("%s." %(str(i+1))) headrow.append("%s." %(str(i+1)))
data_votes.append(headrow) data_votes.append(headrow)
# add result rows # add result rows
@ -547,8 +550,35 @@ def get_assignment(assignment, story):
row = [] row = []
row.append(str(candidate[0][0])) row.append(str(candidate[0][0]))
for votes in candidate[1]: for votes in candidate[1]:
if type(votes) == type(list()):
tmp = "list"
tmp = _("Yes")+": "+str(votes[0])+"\n"
tmp += _("No")+": "+str(votes[1])+"\n"
tmp += _("Abstention")+": "+str(votes[2])
row.append(tmp)
else:
row.append(str(votes)) row.append(str(votes))
data_votes.append(row) data_votes.append(row)
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.votesinvalid)
data_votes.append(row)
# votes cast
row = []
row.append(_("Votes cast"))
for p in polls:
if p.published:
row.append(p.votescast)
data_votes.append(row)
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),
@ -562,10 +592,10 @@ def get_assignment(assignment, story):
# table # table
data = [] data = []
data.append([cell1a,cell1b]) data.append([cell1a,cell1b])
if not table_votes:
data.append([cell2a,cell2b])
if table_votes: if table_votes:
data.append([cell3a,table_votes]) data.append([cell3a,table_votes])
else:
data.append([cell2a,cell2b])
data.append([Spacer(0,0.2*cm),'']) data.append([Spacer(0,0.2*cm),''])
t=Table(data) t=Table(data)
t._argW[0]=4.5*cm t._argW[0]=4.5*cm