From f651ccf3b94ff778dffdfb5fb3184cfd8c1b28d2 Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Fri, 9 May 2014 13:17:19 +0200 Subject: [PATCH] Fixed #1275 (Creating assignment pdf failed) --- openslides/assignment/views.py | 39 +++++++++++++++++++++------------- tests/assignment/test_pdf.py | 22 +++++++++++++++++++ 2 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 tests/assignment/test_pdf.py diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py index b9784c641..5e6e8bde4 100644 --- a/openslides/assignment/views.py +++ b/openslides/assignment/views.py @@ -424,27 +424,36 @@ class AssignmentPDF(PDFView): data_votes.append(row) # Add valid votes row - if poll.votesvalid is not None: - footrow_one = [] - footrow_one.append(_("Valid votes")) - for poll in polls: - footrow_one.append(poll.print_votesvalid()) + footrow_one = [] + footrow_one.append(_("Valid votes")) + votesvalid_is_used = False + for poll in polls: + footrow_one.append(poll.print_votesvalid()) + if poll.votesvalid is not None: + votesvalid_is_used = True + if votesvalid_is_used: data_votes.append(footrow_one) # Add invalid votes row - if poll.votesinvalid is not None: - footrow_two = [] - footrow_two.append(_("Invalid votes")) - for poll in polls: - footrow_two.append(poll.print_votesinvalid()) + footrow_two = [] + footrow_two.append(_("Invalid votes")) + votesinvalid_is_used = False + for poll in polls: + footrow_two.append(poll.print_votesinvalid()) + if poll.votesinvalid is not None: + votesinvalid_is_used = True + if votesinvalid_is_used: data_votes.append(footrow_two) # Add votes cast row - if poll.votescast is not None: - footrow_three = [] - footrow_three.append(_("Votes cast")) - for poll in polls: - footrow_three.append(poll.print_votescast()) + footrow_three = [] + footrow_three.append(_("Votes cast")) + votescast_is_used = False + for poll in polls: + footrow_three.append(poll.print_votescast()) + if poll.votescast is not None: + votescast_is_used = True + if votescast_is_used: data_votes.append(footrow_three) table_votes = Table(data_votes) diff --git a/tests/assignment/test_pdf.py b/tests/assignment/test_pdf.py new file mode 100644 index 000000000..90b3f92be --- /dev/null +++ b/tests/assignment/test_pdf.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +from django.test.client import Client + +from openslides.assignment.models import Assignment +from openslides.participant.models import User +from openslides.utils.test import TestCase + + +class AssignmentPDFTest(TestCase): + """ + Tests for assignment PDF. + """ + def setUp(self): + # Admin + self.admin = User.objects.get(pk=1) + self.admin_client = Client() + self.admin_client.login(username='admin', password='admin') + + def test_render_pdf(self): + Assignment.objects.create(name='assignment_name_ith8qua1Eiferoqu5ju2', description="test", posts=1) + response = self.admin_client.get('/assignment/print/') + self.assertEqual(response.status_code, 200)