Merge pull request #1373 from emanuelschuetze/fix-1326-b

Fixed #1326: Rearranged assignment pdf table cells to prevent a LayoutError.
This commit is contained in:
Norman Jäckel 2014-12-04 15:40:16 +01:00
commit d608dd3095
2 changed files with 123 additions and 133 deletions

View File

@ -15,8 +15,7 @@ Motions:
- Fixed motion detail view template. Added block to enable extra content via - Fixed motion detail view template. Added block to enable extra content via
plugins. plugins.
Assignments: Assignments:
- Fixed PDF when an assignment has a lot of posts. Used only 7 signature - Fixed PDF build error when an election has more than 20 posts or candidates.
lines.
Participants: Participants:
- Fixed participant csv import with group ids: - Fixed participant csv import with group ids:
* Allowed to add multiple groups in csv group id field, e. g. "3,4". * Allowed to add multiple groups in csv group id field, e. g. "3,4".

View File

@ -8,7 +8,7 @@ from django.utils.translation import ungettext
from reportlab.lib import colors from reportlab.lib import colors
from reportlab.lib.units import cm from reportlab.lib.units import cm
from reportlab.platypus import (PageBreak, Paragraph, SimpleDocTemplate, Spacer, from reportlab.platypus import (PageBreak, Paragraph, SimpleDocTemplate, Spacer,
Table, TableStyle) LongTable, Table, TableStyle)
from openslides.agenda.views import CreateRelatedAgendaItemView as _CreateRelatedAgendaItemView from openslides.agenda.views import CreateRelatedAgendaItemView as _CreateRelatedAgendaItemView
from openslides.config.api import config from openslides.config.api import config
@ -346,67 +346,62 @@ class AssignmentPDF(PDFView):
story.append(Paragraph( story.append(Paragraph(
_("Election: %s") % assignment.name, stylesheet['Heading1'])) _("Election: %s") % assignment.name, stylesheet['Heading1']))
story.append(Spacer(0, 0.5 * cm)) story.append(Spacer(0, 0.5 * cm))
# posts
cell1a = [] # Filling table rows...
cell1a.append(Paragraph( data = []
"<font name='Ubuntu-Bold'>%s:</font>" % polls = assignment.poll_set.filter(published=True)
_("Number of available posts"), stylesheet['Bold'])) # 1. posts
cell1b = [] data.append([
cell1b.append(Paragraph(str(assignment.posts), stylesheet['Paragraph'])) Paragraph("%s:" %
# candidates _("Number of available posts"), stylesheet['Bold']),
cell2a = [] Paragraph(str(assignment.posts), stylesheet['Paragraph'])])
cell2a.append(Paragraph(
"<font name='Ubuntu-Bold'>%s:</font><seqreset" # 2a. if no polls available print candidates
" id='counter'>" % _("Candidates"), stylesheet['Heading4'])) if not polls:
cell2b = [] data.append([
Paragraph("%s:<seqreset id='counter'>" %
_("Candidates"), stylesheet['Heading4']),
[]])
for candidate in assignment.candidates: for candidate in assignment.candidates:
cell2b.append(Paragraph( data.append([
"<seq id='counter'/>.&nbsp; %s" % candidate, [],
stylesheet['Signaturefield'])) Paragraph("<seq id='counter'/>.&nbsp; %s" % candidate,
stylesheet['Signaturefield'])])
if assignment.status == "sea": if assignment.status == "sea":
for x in range(0, 7): for x in range(0, 7):
cell2b.append( data.append([
Paragraph( [],
"<seq id='counter'/>.&nbsp; " Paragraph("<seq id='counter'/>.&nbsp; "
"__________________________________________", "__________________________________________",
stylesheet['Signaturefield'])) stylesheet['Signaturefield'])])
cell2b.append(Spacer(0, 0.2 * cm))
# Election result
# 2b. if polls available print election result
if polls:
# Preparing # Preparing
vote_results = assignment.vote_results(only_published=True) vote_results = assignment.vote_results(only_published=True)
polls = assignment.poll_set.filter(published=True)
data_votes = [] data_votes = []
# Left side # Left side
cell3a = [] cell = []
cell3a.append(Paragraph( cell.append(Paragraph(
"%s:" % (_("Election result")), stylesheet['Heading4'])) "%s:" % (_("Election result")), stylesheet['Heading4']))
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 # Add table head row
headrow = [] headrow = []
headrow.append(_("Candidates")) headrow.append(_("Candidates"))
for poll in polls: for poll in polls:
headrow.append("%s." % poll.get_ballot()) headrow.append("%s. %s" % (poll.get_ballot(), _("ballot")))
data_votes.append(headrow) data_votes.append(headrow)
# Add result rows # Add result rows
elected_candidates = list(assignment.elected) elected_candidates = list(assignment.elected)
length = len(vote_results)
for candidate, poll_list in vote_results.iteritems(): for candidate, poll_list in vote_results.iteritems():
row = [] row = []
candidate_string = candidate.clean_name candidate_string = candidate.clean_name
if candidate in elected_candidates: if candidate in elected_candidates:
candidate_string = "* " + candidate_string candidate_string = "* " + candidate_string
if candidate.name_suffix: if candidate.name_suffix and length < 20:
candidate_string += "\n(%s)" % candidate.name_suffix candidate_string += "\n(%s)" % candidate.name_suffix
row.append(candidate_string) row.append(candidate_string)
for vote in poll_list: for vote in poll_list:
@ -467,17 +462,13 @@ class AssignmentPDF(PDFView):
('ROWBACKGROUNDS', (0, 1), (-1, -1), (colors.white, (.9, .9, .9))) ('ROWBACKGROUNDS', (0, 1), (-1, -1), (colors.white, (.9, .9, .9)))
]) ])
) )
data.append([cell, table_votes])
# table if elected_candidates:
data = []
data.append([cell1a, cell1b])
if polls:
data.append([cell3a, table_votes])
data.append(['', '* = ' + _('elected')]) data.append(['', '* = ' + _('elected')])
else:
data.append([cell2a, cell2b]) # table style
data.append([Spacer(0, 0.2 * cm), '']) data.append(['', ''])
t = Table(data) t = LongTable(data)
t._argW[0] = 4.5 * cm t._argW[0] = 4.5 * cm
t._argW[1] = 11 * cm t._argW[1] = 11 * cm
t.setStyle(TableStyle([ t.setStyle(TableStyle([
@ -486,7 +477,7 @@ class AssignmentPDF(PDFView):
story.append(t) story.append(t)
story.append(Spacer(0, 1 * cm)) story.append(Spacer(0, 1 * cm))
# text # election description
story.append( story.append(
Paragraph("%s" % assignment.description.replace('\r\n', '<br/>'), Paragraph("%s" % assignment.description.replace('\r\n', '<br/>'),
stylesheet['Paragraph'])) stylesheet['Paragraph']))