Fixed #948: Use DIN A4 format and wlan ssid qrcode on access data PDF.

This commit is contained in:
Emanuel Schuetze 2013-10-23 23:47:25 +02:00
parent 7fcc786cf9
commit a513477033
5 changed files with 154 additions and 100 deletions

View File

@ -91,6 +91,47 @@ def setup_general_config_page(sender, **kwargs):
label=ugettext_lazy('Allow access for anonymous guest users'), label=ugettext_lazy('Allow access for anonymous guest users'),
required=False)) 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( group_event = ConfigGroup(
title=ugettext_lazy('Event'), title=ugettext_lazy('Event'),
variables=(event_name, event_description, event_date, event_location, event_organizer)) 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( group_system = ConfigGroup(
title=ugettext_lazy('System'), 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( return ConfigGroupedPage(
title=ugettext_noop('General'), title=ugettext_noop('General'),

View File

@ -30,23 +30,22 @@ def setup_participant_config_page(sender, **kwargs):
""" """
Participant config variables. Participant config variables.
""" """
# TODO: Rename config-vars participant_pdf_welcometitle = ConfigVariable(
participant_pdf_system_url = ConfigVariable( name='participant_pdf_welcometitle',
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',
default_value=_('Welcome to OpenSlides!'), default_value=_('Welcome to OpenSlides!'),
form_field=forms.CharField( form_field=forms.CharField(
widget=forms.Textarea(), widget=forms.Textarea(),
required=False, required=False,
label=ugettext_lazy('Welcome text'), label=ugettext_lazy('Title for access data and welcome PDF')))
help_text=ugettext_lazy('Printed in PDF of first time passwords only.')))
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( participant_sort_users_by_first_name = ConfigVariable(
name='participant_sort_users_by_first_name', name='participant_sort_users_by_first_name',
default_value=False, default_value=False,
@ -59,7 +58,7 @@ def setup_participant_config_page(sender, **kwargs):
url='participant', url='participant',
required_permission='config.can_manage', required_permission='config.can_manage',
weight=50, weight=50,
variables=(participant_pdf_system_url, variables=(participant_pdf_welcometitle,
participant_pdf_welcometext, participant_pdf_welcometext,
participant_sort_users_by_first_name)) participant_sort_users_by_first_name))

View File

@ -32,7 +32,7 @@
<ul class="dropdown-menu pull-right"> <ul class="dropdown-menu pull-right">
{% url 'user_settings' as url_usersettings %} {% url 'user_settings' as url_usersettings %}
<li><a href="{% url 'user_print' %}" target="_blank"><i class="icon-list"></i> {% trans 'List of participants' %}</a></li> <li><a href="{% url 'user_print' %}" target="_blank"><i class="icon-list"></i> {% trans 'List of participants' %}</a></li>
<li><a href="{% url 'print_passwords' %}" target="_blank"><i class="icon-th-large"></i> {% trans 'First time passwords' %}</a></li> <li><a href="{% url 'print_passwords' %}" target="_blank"><i class="icon-th-large"></i> {% trans 'List of access data' %}</a></li>
</ul> </ul>
</div> </div>
{% else %} {% else %}

View File

@ -22,8 +22,8 @@ from reportlab.graphics.barcode.qr import QrCodeWidget
from reportlab.graphics.shapes import Drawing from reportlab.graphics.shapes import Drawing
from reportlab.lib import colors from reportlab.lib import colors
from reportlab.lib.units import cm from reportlab.lib.units import cm
from reportlab.platypus import (LongTable, Paragraph, SimpleDocTemplate, from reportlab.platypus import (LongTable, PageBreak, Paragraph, Spacer, Table,
Spacer, Table, TableStyle) TableStyle)
from openslides.config.api import config from openslides.config.api import config
from openslides.projector.projector import Widget from openslides.projector.projector import Widget
@ -239,73 +239,104 @@ class ParticipantsPasswordsPDF(PDFView):
Generate the Welcomepaper for the users. Generate the Welcomepaper for the users.
""" """
permission_required = 'participant.can_manage_participant' permission_required = 'participant.can_manage_participant'
filename = ugettext_lazy("Participant-passwords") filename = ugettext_lazy("Participant-access-data")
top_space = 0 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): def build_document(self, pdf_document, story):
pdf_document.build(story) pdf_document.build(story)
def append_to_pdf(self, story): def append_to_pdf(self, story):
data = [] system_wlan_ssid = config["system_wlan_ssid"] or "-"
participant_pdf_system_url = config["participant_pdf_system_url"] 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"] participant_pdf_welcometext = config["participant_pdf_welcometext"]
if config['participant_sort_users_by_first_name']: if config['participant_sort_users_by_first_name']:
sort = 'first_name' sort = 'first_name'
else: else:
sort = 'last_name' sort = 'last_name'
# create qrcode image object from system url qrcode_size = 2 * cm
qrcode = QrCodeWidget(participant_pdf_system_url) # qrcode for system url
size = 1.5 * cm qrcode_url = QrCodeWidget(system_url)
qrcode.barHeight = size qrcode_url.barHeight = qrcode_size
qrcode.barWidth = size qrcode_url.barWidth = qrcode_size
qrcode.barBorder = 0 qrcode_url.barBorder = 0
draw = Drawing(45, 45) qrcode_url_draw = Drawing(45, 45)
draw.add(qrcode) 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): 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 = []
cell.append(Spacer(0, 0.8 * cm)) cell.append(Paragraph(_("WLAN access data"),
cell.append(Paragraph(_("Account for OpenSlides"), stylesheet['h2']))
stylesheet['Password_title'])) cell.append(Paragraph("%s:" % _("WLAN name (SSID)"),
cell.append(Paragraph(_("for %s") % (user), stylesheet['formfield']))
stylesheet['Password_subtitle'])) 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(Spacer(0, 0.5 * cm))
cell.append(Paragraph(_("User: %s") % (user.username), # OpenSlides access data
stylesheet['Monotype']))
cell.append(
Paragraph(
_("Password: %s")
% (user.default_password), stylesheet['Monotype']))
cell.append(
Paragraph(participant_pdf_system_url, stylesheet['Monotype']))
cell.append(draw)
cell2 = [] cell2 = []
cell2.append(Spacer(0, 0.8 * cm)) cell2.append(Paragraph(_("OpenSlides access data"),
if participant_pdf_welcometext is not None: stylesheet['h2']))
cell2.append(Paragraph( cell2.append(Paragraph("%s:" % _("Username"),
participant_pdf_welcometext.replace('\r\n', '<br/>'), stylesheet['formfield']))
stylesheet['Ballot_subtitle'])) 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]) data.append([cell, cell2])
# add empty table line if no participants available
if not data:
data.append(['', ''])
# build table # build table
t = Table(data, 10.5 * cm, 7.42 * cm) table = Table(data)
t.setStyle(TableStyle([ table._argW[0] = 8 * cm
('LEFTPADDING', (0, 0), (0, -1), 30), table._argW[1] = 8 * cm
('LINEBELOW', (0, 0), (-1, 0), 0.25, colors.grey), table.setStyle(TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')]))
('LINEBELOW', (0, 1), (-1, 1), 0.25, colors.grey), story.append(table)
('LINEBELOW', (0, 1), (-1, -1), 0.25, colors.grey), story.append(Spacer(0, 2 * cm))
('VALIGN', (0, 0), (-1, -1), 'TOP'),
])) # welcome title and text
story.append(t) story.append(Paragraph(participant_pdf_welcometitle,
stylesheet['h2']))
story.append(Paragraph(participant_pdf_welcometext.replace('\r\n', '<br/>'),
stylesheet['Paragraph12']))
story.append(PageBreak())
class UserImportView(FormView): class UserImportView(FormView):

View File

@ -52,6 +52,11 @@ stylesheet.add(ParagraphStyle(
leading=14, leading=14,
spaceAfter=15 spaceAfter=15
)) ))
stylesheet.add(ParagraphStyle(
name='Paragraph12',
parent=stylesheet['Paragraph'],
fontSize=12
))
stylesheet.add(ParagraphStyle( stylesheet.add(ParagraphStyle(
name='InnerParagraph', name='InnerParagraph',
parent=stylesheet['Normal'], parent=stylesheet['Normal'],
@ -138,7 +143,7 @@ stylesheet.add(ParagraphStyle(
parent=stylesheet['Bold'], parent=stylesheet['Bold'],
fontSize=10, fontSize=10,
leading=20, leading=20,
)) ), alias='h4')
stylesheet.add(ParagraphStyle( stylesheet.add(ParagraphStyle(
name='Item', name='Item',
parent=stylesheet['Normal'], parent=stylesheet['Normal'],
@ -216,45 +221,23 @@ stylesheet.add(ParagraphStyle(name='Ballot_option_group_right',
leftIndent=49), leftIndent=49),
) )
# Password paper stylesheets # Password paper stylesheets
stylesheet.add(ParagraphStyle(name='Password_title', stylesheet.add(ParagraphStyle(name='formfield',
parent=stylesheet['Ballot_title'], parent=stylesheet['Normal'],
fontSize=12,
leading=18,
leftIndent=0), leftIndent=0),
) )
stylesheet.add(ParagraphStyle(name='Password_subtitle', stylesheet.add(ParagraphStyle(name='formfield_value',
parent=stylesheet['Ballot_subtitle'],
leftIndent=0),
)
stylesheet.add(ParagraphStyle(name='Monotype',
parent=stylesheet['Normal'], parent=stylesheet['Normal'],
fontName='Courier', fontName='Courier',
fontSize=12, fontSize=12,
leading=24, leading=28,
leftIndent=0), leftIndent=10),
) )
stylesheet.add(ParagraphStyle(name='Badge_title', stylesheet.add(ParagraphStyle(name='qrcode_comment',
parent=stylesheet['Bold'], parent=stylesheet['Small'],
fontSize=16, spaceBefore=6),
leading=22,
leftIndent=30),
) )
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): def firstPage(canvas, doc):