Merge pull request #1947 from normanjaeckel/AssignmentPDF

Fixed assignment PDF. Fixed #1940.
This commit is contained in:
Emanuel Schütze 2016-02-05 22:30:23 +01:00
commit fc35468faf
2 changed files with 28 additions and 3 deletions

View File

@ -336,13 +336,13 @@ class AssignmentPDF(PDFView):
# Add result rows # Add result rows
elected_candidates = list(assignment.elected) elected_candidates = list(assignment.elected)
length = len(vote_results) length = len(vote_results)
for candidate, poll_list in vote_results.iteritems(): for candidate, poll_list in vote_results.items():
row = [] row = []
candidate_string = candidate.get_short_name() candidate_string = candidate.get_short_name()
if candidate in elected_candidates: if candidate in elected_candidates:
candidate_string = "* " + candidate_string candidate_string = "* " + candidate_string
if candidate.name_suffix and length < 20: if candidate.structure_level and length < 20:
candidate_string += "\n(%s)" % candidate.name_suffix candidate_string += "\n(%s)" % candidate.structure_level
row.append(candidate_string) row.append(candidate_string)
for vote in poll_list: for vote in poll_list:
if vote is None: if vote is None:

View File

@ -0,0 +1,25 @@
from django.contrib.auth import get_user_model
from django.core.urlresolvers import reverse
from rest_framework import status
from rest_framework.test import APIClient
from openslides.assignments.models import Assignment
from openslides.utils.test import TestCase
class PDF(TestCase):
"""
Tests assignment PDF.
"""
def setUp(self):
self.client = APIClient()
self.client.login(username='admin', password='admin')
self.admin = get_user_model().objects.get(username='admin')
self.assignment = Assignment.objects.create(title='test_assignment_OxieG7BioChahteY4aeM', open_posts=1)
def test_pdf_with_ballot(self):
self.assignment.set_candidate(self.admin)
self.assignment.create_poll()
self.assignment.polls.all()[0].set_published(True)
response = self.client.get(reverse('assignments_pdf'))
self.assertEqual(response.status_code, status.HTTP_200_OK)