Merge pull request #1497 from ostcar/users-password-pdf

Fixed users password pdf view.
This commit is contained in:
Norman Jäckel 2015-02-27 12:53:18 +01:00
commit d0d01ed71c
3 changed files with 27 additions and 7 deletions

View File

@ -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

View File

@ -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,
)

View File

@ -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.")