Fixed index error while generating assignment pdf.
This commit is contained in:
parent
7ef4013b4b
commit
9917e2f545
@ -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,40 +534,68 @@ 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']))
|
||||||
data_votes = []
|
if len(results[0][1]) > 0:
|
||||||
# add table head row
|
data_votes = []
|
||||||
headrow = []
|
# add table head row
|
||||||
headrow.append(_("Candidates"))
|
headrow = []
|
||||||
for i in range (0,len(results[1][1])):
|
headrow.append(_("Candidates"))
|
||||||
headrow.append("%s." %(str(i+1)))
|
for i in range (0,len(results[0][1])):
|
||||||
data_votes.append(headrow)
|
headrow.append("%s." %(str(i+1)))
|
||||||
# add result rows
|
data_votes.append(headrow)
|
||||||
for candidate in results:
|
# add result rows
|
||||||
|
for candidate in results:
|
||||||
|
row = []
|
||||||
|
row.append(str(candidate[0][0]))
|
||||||
|
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))
|
||||||
|
|
||||||
|
data_votes.append(row)
|
||||||
|
polls = []
|
||||||
|
for poll in assignment.poll_set.filter(assignment=assignment):
|
||||||
|
polls.append(poll)
|
||||||
|
# votes invalid
|
||||||
row = []
|
row = []
|
||||||
row.append(str(candidate[0][0]))
|
row.append(_("Invalid votes"))
|
||||||
for votes in candidate[1]:
|
for p in polls:
|
||||||
row.append(str(votes))
|
if p.published:
|
||||||
|
row.append(p.votesinvalid)
|
||||||
data_votes.append(row)
|
data_votes.append(row)
|
||||||
table_votes=Table(data_votes)
|
|
||||||
table_votes.setStyle( TableStyle([
|
# votes cast
|
||||||
('GRID', (0,0), (-1,-1), 0.5, colors.grey),
|
row = []
|
||||||
('VALIGN',(0,0),(-1,-1), 'TOP'),
|
row.append(_("Votes cast"))
|
||||||
('LINEABOVE',(0,0),(-1,0),2,colors.black),
|
for p in polls:
|
||||||
('LINEABOVE',(0,1),(-1,1),1,colors.black),
|
if p.published:
|
||||||
('LINEBELOW',(0,-1),(-1,-1),2,colors.black),
|
row.append(p.votescast)
|
||||||
('ROWBACKGROUNDS', (0, 1), (-1, -1), (colors.white, (.9, .9, .9))),
|
data_votes.append(row)
|
||||||
]))
|
|
||||||
|
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))),
|
||||||
|
]))
|
||||||
|
|
||||||
# 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
|
||||||
|
Loading…
Reference in New Issue
Block a user