From 787343d6512c054e401b256d6071f08bd47fcd62 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Fri, 27 Feb 2015 09:20:49 +0100 Subject: [PATCH] Fixes users password PDF view. Fixes: #1496 --- openslides/users/pdf.py | 16 +++++++++++----- openslides/users/views.py | 4 ++-- tests/integration/users/test_views.py | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/openslides/users/pdf.py b/openslides/users/pdf.py index 6a677e528..eae78e16f 100644 --- a/openslides/users/pdf.py +++ b/openslides/users/pdf.py @@ -5,8 +5,14 @@ from reportlab.graphics.barcode.qr import QrCodeWidget from reportlab.graphics.shapes import Drawing from reportlab.lib import colors from reportlab.lib.units import cm -from reportlab.platypus import (LongTable, PageBreak, Paragraph, Spacer, Table, - TableStyle) +from reportlab.platypus import ( + LongTable, + PageBreak, + Paragraph, + Spacer, + Table, + TableStyle, +) from openslides.config.api import config from openslides.utils.pdf import stylesheet @@ -16,7 +22,7 @@ from .models import User def users_to_pdf(pdf): """ - Create a list of all users as PDF + Create a list of all users as PDF. """ data = [['#', _('Title'), _('Last Name'), _('First Name'), _('Structure level'), _('Group')]] @@ -52,7 +58,7 @@ def users_to_pdf(pdf): def users_passwords_to_pdf(pdf): """ - Create access data sheets for all users as PDF + Create access data sheets for all users as PDF. """ users_pdf_wlan_ssid = config["users_pdf_wlan_ssid"] or "-" users_pdf_wlan_password = config["users_pdf_wlan_password"] or "-" @@ -82,7 +88,7 @@ def users_passwords_to_pdf(pdf): qrcode_wlan_draw.add(qrcode_wlan) for user in User.objects.all().order_by(sort): - pdf.append(Paragraph(escape(user), stylesheet['h1'])) + pdf.append(Paragraph(escape(user.get_full_name()), stylesheet['h1'])) pdf.append(Spacer(0, 1 * cm)) data = [] # WLAN access data diff --git a/openslides/users/views.py b/openslides/users/views.py index 6ab83ccfa..d64f60ffd 100644 --- a/openslides/users/views.py +++ b/openslides/users/views.py @@ -8,12 +8,12 @@ from rest_framework import status from openslides.utils.rest_api import ModelViewSet, Response from openslides.utils.views import ( + APIView, CSVImportView, FormView, LoginMixin, PDFView, UpdateView, - APIView ) from .csv_import import import_users @@ -24,7 +24,7 @@ from .serializers import ( GroupSerializer, UserCreateUpdateSerializer, UserFullSerializer, - UserShortSerializer + UserShortSerializer, ) diff --git a/tests/integration/users/test_views.py b/tests/integration/users/test_views.py index 08659ca6a..97d3b2bb0 100644 --- a/tests/integration/users/test_views.py +++ b/tests/integration/users/test_views.py @@ -87,3 +87,17 @@ class TestUserLoginView(TestCase): self.assertEqual( json.loads(response.content.decode('utf-8')), {'success': False}) + + +class TestUsersPasswordsPDF(TestCase): + def test_get(self): + """ + Tests that the view returns the status code 200. + """ + self.client.login(username='admin', password='admin') + response = self.client.get('/users/passwords/print/') + + self.assertEqual( + response.status_code, + 200, + "The status code of the user password PDF view should be 200.")