Merge pull request #571 from emanuelschuetze/qrcode

New feature: qr-code for system url on participants password pdf.
This commit is contained in:
Oskar Hahn 2013-03-22 23:42:44 -07:00
commit d424176def
3 changed files with 41 additions and 15 deletions

View File

@ -10,13 +10,21 @@
:license: GNU GPL, see LICENSE for more details. :license: GNU GPL, see LICENSE for more details.
""" """
try:
import qrcode
except ImportError:
draw_qrcode = False
else:
draw_qrcode = True
from cStringIO import StringIO
from urllib import urlencode from urllib import urlencode
from urlparse import parse_qs from urlparse import parse_qs
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 ( from reportlab.platypus import (
SimpleDocTemplate, Paragraph, LongTable, Spacer, Table, TableStyle) SimpleDocTemplate, Paragraph, LongTable, Spacer, Table, TableStyle, Image)
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
@ -229,13 +237,21 @@ class ParticipantsPasswordsPDF(PDFView):
sort = 'first_name' sort = 'first_name'
else: else:
sort = 'last_name' sort = 'last_name'
# create qrcode image object from system url
if draw_qrcode:
qrcode_img = qrcode.make(participant_pdf_system_url)
img_stream = StringIO()
qrcode_img.save(img_stream, 'PNG')
img_stream.seek(0)
size = 2*cm
I = Image(img_stream, width=size, height=size)
for user in User.objects.all().order_by(sort): for user in User.objects.all().order_by(sort):
cell = [] cell = []
cell.append(Spacer(0, 0.8 * cm)) cell.append(Spacer(0, 0.8 * cm))
cell.append(Paragraph(_("Account for OpenSlides"), cell.append(Paragraph(_("Account for OpenSlides"),
stylesheet['Ballot_title'])) stylesheet['Password_title']))
cell.append(Paragraph(_("for %s") % (user), cell.append(Paragraph(_("for %s") % (user),
stylesheet['Ballot_subtitle'])) stylesheet['Password_subtitle']))
cell.append(Spacer(0, 0.5 * cm)) cell.append(Spacer(0, 0.5 * cm))
cell.append(Paragraph(_("User: %s") % (user.username), cell.append(Paragraph(_("User: %s") % (user.username),
stylesheet['Monotype'])) stylesheet['Monotype']))
@ -243,12 +259,10 @@ class ParticipantsPasswordsPDF(PDFView):
Paragraph( Paragraph(
_("Password: %s") _("Password: %s")
% (user.default_password), stylesheet['Monotype'])) % (user.default_password), stylesheet['Monotype']))
cell.append(Spacer(0, 0.5 * cm))
cell.append( cell.append(
Paragraph( Paragraph(participant_pdf_system_url, stylesheet['Monotype']))
_("URL: %s") % (participant_pdf_system_url), if draw_qrcode:
stylesheet['Ballot_option'])) cell.append(I)
cell.append(Spacer(0, 0.5 * cm))
cell2 = [] cell2 = []
cell2.append(Spacer(0, 0.8 * cm)) cell2.append(Spacer(0, 0.8 * cm))
if participant_pdf_welcometext is not None: if participant_pdf_welcometext is not None:
@ -264,6 +278,7 @@ class ParticipantsPasswordsPDF(PDFView):
# build table # build table
t = Table(data, 10.5 * cm, 7.42 * cm) t = Table(data, 10.5 * cm, 7.42 * cm)
t.setStyle(TableStyle([ t.setStyle(TableStyle([
('LEFTPADDING', (0, 0), (0, -1), 30),
('LINEBELOW', (0, 0), (-1, 0), 0.25, colors.grey), ('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),
('LINEBELOW', (0, 1), (-1, -1), 0.25, colors.grey), ('LINEBELOW', (0, 1), (-1, -1), 0.25, colors.grey),

View File

@ -147,13 +147,6 @@ stylesheet.add(ParagraphStyle(name='Ballot_option',
leading=24, leading=24,
leftIndent=30), leftIndent=30),
) )
stylesheet.add(ParagraphStyle(name='Monotype',
parent=stylesheet['Normal'],
fontName='Courier',
fontSize=12,
leading=24,
leftIndent=30),
)
stylesheet.add(ParagraphStyle(name='Ballot_option_name', stylesheet.add(ParagraphStyle(name='Ballot_option_name',
parent=stylesheet['Normal'], parent=stylesheet['Normal'],
fontSize=12, fontSize=12,
@ -179,6 +172,22 @@ stylesheet.add(ParagraphStyle(name='Ballot_option_group_right',
leading=16, leading=16,
leftIndent=49), leftIndent=49),
) )
# Password paper stylesheets
stylesheet.add(ParagraphStyle(name='Password_title',
parent=stylesheet['Ballot_title'],
leftIndent=0),
)
stylesheet.add(ParagraphStyle(name='Password_subtitle',
parent=stylesheet['Ballot_subtitle'],
leftIndent=0),
)
stylesheet.add(ParagraphStyle(name='Monotype',
parent=stylesheet['Normal'],
fontName='Courier',
fontSize=12,
leading=24,
leftIndent=0),
)
stylesheet.add(ParagraphStyle(name='Badge_title', stylesheet.add(ParagraphStyle(name='Badge_title',
parent=stylesheet['Bold'], parent=stylesheet['Bold'],
fontSize=16, fontSize=16,

View File

@ -6,3 +6,5 @@ coverage==3.6
django-discover-runner==0.3 django-discover-runner==0.3
pep8==1.4.4 pep8==1.4.4
tornado==2.4.1 tornado==2.4.1
qrcode==2.5.1