From a5134770333c62f4388e86b69c99cb2dbae4e5f4 Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Wed, 23 Oct 2013 23:47:25 +0200 Subject: [PATCH] Fixed #948: Use DIN A4 format and wlan ssid qrcode on access data PDF. --- openslides/core/signals.py | 43 +++++- openslides/participant/signals.py | 27 ++-- .../templates/participant/overview.html | 2 +- openslides/participant/views.py | 133 +++++++++++------- openslides/utils/pdf.py | 49 +++---- 5 files changed, 154 insertions(+), 100 deletions(-) diff --git a/openslides/core/signals.py b/openslides/core/signals.py index bd0ac21b9..cba91f8b6 100644 --- a/openslides/core/signals.py +++ b/openslides/core/signals.py @@ -91,6 +91,47 @@ def setup_general_config_page(sender, **kwargs): label=ugettext_lazy('Allow access for anonymous guest users'), required=False)) + system_url = ConfigVariable( + name='system_url', + default_value='http://example.com:8000', + form_field=forms.CharField( + widget=forms.TextInput(), + required=False, + label=ugettext_lazy('System URL'), + help_text=ugettext_lazy('Used for QRCode in PDF of access data.'))) + + system_wlan_ssid = ConfigVariable( + name='system_wlan_ssid', + default_value='', + form_field=forms.CharField( + widget=forms.TextInput(), + required=False, + label=ugettext_lazy('WLAN name (SSID)'), + help_text=ugettext_lazy('Used for WLAN QRCode in PDF of access data.'))) + + system_wlan_password = ConfigVariable( + name='system_wlan_password', + default_value='', + form_field=forms.CharField( + widget=forms.TextInput(), + required=False, + label=ugettext_lazy('WLAN password'), + help_text=ugettext_lazy('Used for WLAN QRCode in PDF of access data.'))) + + system_wlan_encryption = ConfigVariable( + name='system_wlan_encryption', + default_value='', + form_field=forms.ChoiceField( + widget=forms.Select(), + required=False, + label=ugettext_lazy('WLAN encryption'), + help_text=ugettext_lazy('Used for WLAN QRCode in PDF of access data.'), + choices=( + ('', ugettext_lazy('---------')), + ('WEP', ugettext_lazy('WEP')), + ('WPA', ugettext_lazy('WPA/WPA2')), + ('nopass', ugettext_lazy('No encryption'))))) + group_event = ConfigGroup( title=ugettext_lazy('Event'), variables=(event_name, event_description, event_date, event_location, event_organizer)) @@ -101,7 +142,7 @@ def setup_general_config_page(sender, **kwargs): group_system = ConfigGroup( title=ugettext_lazy('System'), - variables=(system_enable_anonymous,)) + variables=(system_enable_anonymous, system_url, system_wlan_ssid, system_wlan_password, system_wlan_encryption)) return ConfigGroupedPage( title=ugettext_noop('General'), diff --git a/openslides/participant/signals.py b/openslides/participant/signals.py index fbd3e1393..c57fee2bf 100644 --- a/openslides/participant/signals.py +++ b/openslides/participant/signals.py @@ -30,23 +30,22 @@ def setup_participant_config_page(sender, **kwargs): """ Participant config variables. """ - # TODO: Rename config-vars - participant_pdf_system_url = ConfigVariable( - name='participant_pdf_system_url', - default_value='http://example.com:8000', - form_field=forms.CharField( - widget=forms.TextInput(), - required=False, - label=ugettext_lazy('System URL'), - help_text=ugettext_lazy('Printed in PDF of first time passwords only.'))) - participant_pdf_welcometext = ConfigVariable( - name='participant_pdf_welcometext', + participant_pdf_welcometitle = ConfigVariable( + name='participant_pdf_welcometitle', default_value=_('Welcome to OpenSlides!'), form_field=forms.CharField( widget=forms.Textarea(), required=False, - label=ugettext_lazy('Welcome text'), - help_text=ugettext_lazy('Printed in PDF of first time passwords only.'))) + label=ugettext_lazy('Title for access data and welcome PDF'))) + + participant_pdf_welcometext = ConfigVariable( + name='participant_pdf_welcometext', + default_value=_('[Place for your welcome and help text.]'), + form_field=forms.CharField( + widget=forms.Textarea(), + required=False, + label=ugettext_lazy('Help text for access data and welcome PDF'))) + participant_sort_users_by_first_name = ConfigVariable( name='participant_sort_users_by_first_name', default_value=False, @@ -59,7 +58,7 @@ def setup_participant_config_page(sender, **kwargs): url='participant', required_permission='config.can_manage', weight=50, - variables=(participant_pdf_system_url, + variables=(participant_pdf_welcometitle, participant_pdf_welcometext, participant_sort_users_by_first_name)) diff --git a/openslides/participant/templates/participant/overview.html b/openslides/participant/templates/participant/overview.html index 8f9ae8349..210d4a152 100644 --- a/openslides/participant/templates/participant/overview.html +++ b/openslides/participant/templates/participant/overview.html @@ -32,7 +32,7 @@ {% else %} diff --git a/openslides/participant/views.py b/openslides/participant/views.py index 7d2288939..18bf85d16 100644 --- a/openslides/participant/views.py +++ b/openslides/participant/views.py @@ -22,8 +22,8 @@ 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, Paragraph, SimpleDocTemplate, - Spacer, Table, TableStyle) +from reportlab.platypus import (LongTable, PageBreak, Paragraph, Spacer, Table, + TableStyle) from openslides.config.api import config from openslides.projector.projector import Widget @@ -239,73 +239,104 @@ class ParticipantsPasswordsPDF(PDFView): Generate the Welcomepaper for the users. """ permission_required = 'participant.can_manage_participant' - filename = ugettext_lazy("Participant-passwords") + filename = ugettext_lazy("Participant-access-data") top_space = 0 - def get_template(self, buffer): - return SimpleDocTemplate( - buffer, topMargin=-6, bottomMargin=-6, - leftMargin=0, rightMargin=0, showBoundary=False) - def build_document(self, pdf_document, story): pdf_document.build(story) def append_to_pdf(self, story): - data = [] - participant_pdf_system_url = config["participant_pdf_system_url"] + system_wlan_ssid = config["system_wlan_ssid"] or "-" + system_wlan_password = config["system_wlan_password"] or "-" + system_wlan_encryption = config["system_wlan_encryption"] or "-" + system_url = config["system_url"] or "-" + participant_pdf_welcometitle = config["participant_pdf_welcometitle"] participant_pdf_welcometext = config["participant_pdf_welcometext"] if config['participant_sort_users_by_first_name']: sort = 'first_name' else: sort = 'last_name' - # create qrcode image object from system url - qrcode = QrCodeWidget(participant_pdf_system_url) - size = 1.5 * cm - qrcode.barHeight = size - qrcode.barWidth = size - qrcode.barBorder = 0 - draw = Drawing(45, 45) - draw.add(qrcode) + qrcode_size = 2 * cm + # qrcode for system url + qrcode_url = QrCodeWidget(system_url) + qrcode_url.barHeight = qrcode_size + qrcode_url.barWidth = qrcode_size + qrcode_url.barBorder = 0 + qrcode_url_draw = Drawing(45, 45) + qrcode_url_draw.add(qrcode_url) + # qrcode for wlan + text = "WIFI:S:%s;T:%s;P:%s;;" % (system_wlan_ssid, system_wlan_encryption, system_wlan_password) + qrcode_wlan = QrCodeWidget(text) + qrcode_wlan.barHeight = qrcode_size + qrcode_wlan.barWidth = qrcode_size + qrcode_wlan.barBorder = 0 + qrcode_wlan_draw = Drawing(45, 45) + qrcode_wlan_draw.add(qrcode_wlan) for user in User.objects.all().order_by(sort): + story.append(Paragraph(unicode(user), stylesheet['h1'])) + story.append(Spacer(0, 1 * cm)) + data = [] + # WLAN access data cell = [] - cell.append(Spacer(0, 0.8 * cm)) - cell.append(Paragraph(_("Account for OpenSlides"), - stylesheet['Password_title'])) - cell.append(Paragraph(_("for %s") % (user), - stylesheet['Password_subtitle'])) + cell.append(Paragraph(_("WLAN access data"), + stylesheet['h2'])) + cell.append(Paragraph("%s:" % _("WLAN name (SSID)"), + stylesheet['formfield'])) + cell.append(Paragraph(system_wlan_ssid, + stylesheet['formfield_value'])) + cell.append(Paragraph("%s:" % _("WLAN password"), + stylesheet['formfield'])) + cell.append(Paragraph(system_wlan_password, + stylesheet['formfield_value'])) + cell.append(Paragraph("%s:" % _("WLAN encryption"), + stylesheet['formfield'])) + cell.append(Paragraph(system_wlan_encryption, + stylesheet['formfield_value'])) cell.append(Spacer(0, 0.5 * cm)) - cell.append(Paragraph(_("User: %s") % (user.username), - stylesheet['Monotype'])) - cell.append( - Paragraph( - _("Password: %s") - % (user.default_password), stylesheet['Monotype'])) - cell.append( - Paragraph(participant_pdf_system_url, stylesheet['Monotype'])) - cell.append(draw) + # OpenSlides access data cell2 = [] - cell2.append(Spacer(0, 0.8 * cm)) - if participant_pdf_welcometext is not None: - cell2.append(Paragraph( - participant_pdf_welcometext.replace('\r\n', '
'), - stylesheet['Ballot_subtitle'])) - + cell2.append(Paragraph(_("OpenSlides access data"), + stylesheet['h2'])) + cell2.append(Paragraph("%s:" % _("Username"), + stylesheet['formfield'])) + cell2.append(Paragraph(user.username, + stylesheet['formfield_value'])) + cell2.append(Paragraph("%s:" % _("Password"), + stylesheet['formfield'])) + cell2.append(Paragraph(user.default_password, + stylesheet['formfield_value'])) + cell2.append(Paragraph("URL:", + stylesheet['formfield'])) + cell2.append(Paragraph(system_url, + stylesheet['formfield_value'])) data.append([cell, cell2]) + # QRCodes + cell = [] + if system_wlan_ssid != "-" and system_wlan_encryption != "-": + cell.append(qrcode_wlan_draw) + cell.append(Paragraph(_("Scan this QRCode to connect WLAN."), + stylesheet['qrcode_comment'])) + cell2 = [] + if system_url != "-": + cell2.append(qrcode_url_draw) + cell2.append(Paragraph(_("Scan this QRCode to open URL."), + stylesheet['qrcode_comment'])) + data.append([cell, cell2]) + # build table + table = Table(data) + table._argW[0] = 8 * cm + table._argW[1] = 8 * cm + table.setStyle(TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')])) + story.append(table) + story.append(Spacer(0, 2 * cm)) - # add empty table line if no participants available - if not data: - data.append(['', '']) - # build table - t = Table(data, 10.5 * cm, 7.42 * cm) - t.setStyle(TableStyle([ - ('LEFTPADDING', (0, 0), (0, -1), 30), - ('LINEBELOW', (0, 0), (-1, 0), 0.25, colors.grey), - ('LINEBELOW', (0, 1), (-1, 1), 0.25, colors.grey), - ('LINEBELOW', (0, 1), (-1, -1), 0.25, colors.grey), - ('VALIGN', (0, 0), (-1, -1), 'TOP'), - ])) - story.append(t) + # welcome title and text + story.append(Paragraph(participant_pdf_welcometitle, + stylesheet['h2'])) + story.append(Paragraph(participant_pdf_welcometext.replace('\r\n', '
'), + stylesheet['Paragraph12'])) + story.append(PageBreak()) class UserImportView(FormView): diff --git a/openslides/utils/pdf.py b/openslides/utils/pdf.py index cab81057c..6ecfaad23 100644 --- a/openslides/utils/pdf.py +++ b/openslides/utils/pdf.py @@ -52,6 +52,11 @@ stylesheet.add(ParagraphStyle( leading=14, spaceAfter=15 )) +stylesheet.add(ParagraphStyle( + name='Paragraph12', + parent=stylesheet['Paragraph'], + fontSize=12 +)) stylesheet.add(ParagraphStyle( name='InnerParagraph', parent=stylesheet['Normal'], @@ -138,7 +143,7 @@ stylesheet.add(ParagraphStyle( parent=stylesheet['Bold'], fontSize=10, leading=20, -)) +), alias='h4') stylesheet.add(ParagraphStyle( name='Item', parent=stylesheet['Normal'], @@ -216,45 +221,23 @@ stylesheet.add(ParagraphStyle(name='Ballot_option_group_right', leftIndent=49), ) # Password paper stylesheets -stylesheet.add(ParagraphStyle(name='Password_title', - parent=stylesheet['Ballot_title'], +stylesheet.add(ParagraphStyle(name='formfield', + parent=stylesheet['Normal'], + fontSize=12, + leading=18, leftIndent=0), ) -stylesheet.add(ParagraphStyle(name='Password_subtitle', - parent=stylesheet['Ballot_subtitle'], - leftIndent=0), - ) -stylesheet.add(ParagraphStyle(name='Monotype', +stylesheet.add(ParagraphStyle(name='formfield_value', parent=stylesheet['Normal'], fontName='Courier', fontSize=12, - leading=24, - leftIndent=0), + leading=28, + leftIndent=10), ) -stylesheet.add(ParagraphStyle(name='Badge_title', - parent=stylesheet['Bold'], - fontSize=16, - leading=22, - leftIndent=30), +stylesheet.add(ParagraphStyle(name='qrcode_comment', + parent=stylesheet['Small'], + spaceBefore=6), ) -stylesheet.add(ParagraphStyle(name='Badge_subtitle', - parent=stylesheet['Normal'], - fontSize=12, - leading=24, - leftIndent=30), - ) -stylesheet.add(ParagraphStyle( - name='Badge_italic', - parent=stylesheet['Italic'], - fontSize=12, - leading=24, - leftIndent=30, -)) -stylesheet.add(ParagraphStyle( - name='Badge_qrcode', - fontSize=12, - leftIndent=190, -)) def firstPage(canvas, doc):