2011-07-31 10:46:29 +02:00
|
|
|
from datetime import datetime
|
2012-07-10 13:19:12 +02:00
|
|
|
from os.path import join as path_join
|
2011-09-04 08:23:03 +02:00
|
|
|
|
2013-09-25 10:01:01 +02:00
|
|
|
from django.conf import settings
|
|
|
|
from django.utils import formats
|
|
|
|
from django.utils.translation import ugettext as _
|
2013-04-07 19:46:28 +02:00
|
|
|
from reportlab.lib import colors
|
2013-09-25 10:01:01 +02:00
|
|
|
from reportlab.lib.styles import ParagraphStyle, StyleSheet1
|
2012-07-10 13:19:12 +02:00
|
|
|
from reportlab.lib.units import cm
|
2011-07-31 10:46:29 +02:00
|
|
|
from reportlab.pdfbase import pdfmetrics
|
|
|
|
from reportlab.pdfbase.ttfonts import TTFont
|
2012-07-10 13:19:12 +02:00
|
|
|
from reportlab.rl_config import defaultPageSize
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2015-06-29 12:08:15 +02:00
|
|
|
from openslides.core.config import config
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
# register new truetype fonts
|
2012-11-24 14:01:21 +01:00
|
|
|
pdfmetrics.registerFont(TTFont(
|
2014-01-14 23:22:29 +01:00
|
|
|
'Ubuntu', path_join(settings.SITE_ROOT, 'core/static/fonts/Ubuntu-R.ttf')))
|
2012-11-24 14:01:21 +01:00
|
|
|
pdfmetrics.registerFont(TTFont(
|
2014-01-14 23:22:29 +01:00
|
|
|
'Ubuntu-Bold', path_join(settings.SITE_ROOT, 'core/static/fonts/Ubuntu-B.ttf')))
|
2014-05-18 13:55:50 +02:00
|
|
|
pdfmetrics.registerFont(TTFont(
|
|
|
|
'Ubuntu-Italic', path_join(settings.SITE_ROOT, 'core/static/fonts/Ubuntu-RI.ttf')))
|
2014-03-07 00:17:25 +01:00
|
|
|
pdfmetrics.registerFont(TTFont(
|
2014-04-07 22:35:52 +02:00
|
|
|
'circlefont', path_join(settings.SITE_ROOT, 'core/static/fonts/circle.ttf')))
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2014-05-18 13:55:50 +02:00
|
|
|
pdfmetrics.registerFontFamily('Ubuntu', normal='Ubuntu', bold='Ubuntu-Bold', italic='Ubuntu-Italic')
|
2011-09-06 09:17:39 +02:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
# set style information
|
2012-11-24 14:01:21 +01:00
|
|
|
PAGE_HEIGHT = defaultPageSize[1]
|
2012-07-10 13:19:12 +02:00
|
|
|
PAGE_WIDTH = defaultPageSize[0]
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2011-09-06 09:17:39 +02:00
|
|
|
|
2011-09-02 15:54:13 +02:00
|
|
|
# set custom stylesheets
|
|
|
|
stylesheet = StyleSheet1()
|
2012-07-10 13:19:12 +02:00
|
|
|
stylesheet.add(ParagraphStyle(
|
|
|
|
name='Normal',
|
2014-05-18 13:55:50 +02:00
|
|
|
fontName='Ubuntu',
|
2012-07-10 13:19:12 +02:00
|
|
|
fontSize=10,
|
|
|
|
leading=12,
|
|
|
|
))
|
|
|
|
stylesheet.add(ParagraphStyle(
|
|
|
|
name='Paragraph',
|
|
|
|
parent=stylesheet['Normal'],
|
|
|
|
leading=14,
|
|
|
|
spaceAfter=15
|
|
|
|
))
|
2013-10-23 23:47:25 +02:00
|
|
|
stylesheet.add(ParagraphStyle(
|
|
|
|
name='Paragraph12',
|
|
|
|
parent=stylesheet['Paragraph'],
|
|
|
|
fontSize=12
|
|
|
|
))
|
2013-04-07 19:46:28 +02:00
|
|
|
stylesheet.add(ParagraphStyle(
|
|
|
|
name='InnerParagraph',
|
|
|
|
parent=stylesheet['Normal'],
|
|
|
|
leading=14,
|
|
|
|
spaceBefore=5,
|
|
|
|
spaceAfter=5,
|
|
|
|
bulletIndent=-15,
|
|
|
|
bulletFontSize=8,
|
|
|
|
bulletColor=colors.grey
|
|
|
|
))
|
|
|
|
stylesheet.add(ParagraphStyle(
|
|
|
|
name='InnerListParagraph',
|
|
|
|
parent=stylesheet['InnerParagraph'],
|
|
|
|
bulletIndent=10,
|
|
|
|
bulletFontSize=10,
|
|
|
|
bulletColor=colors.black,
|
2013-04-15 21:12:29 +02:00
|
|
|
leftIndent=30
|
2013-04-07 19:46:28 +02:00
|
|
|
))
|
|
|
|
stylesheet.add(ParagraphStyle(
|
|
|
|
name='InnerMonotypeParagraph',
|
|
|
|
parent=stylesheet['InnerParagraph'],
|
|
|
|
fontName='Courier',
|
|
|
|
))
|
|
|
|
stylesheet.add(ParagraphStyle(
|
|
|
|
name='InnerH1Paragraph',
|
|
|
|
parent=stylesheet['InnerParagraph'],
|
|
|
|
fontName='Ubuntu-Bold',
|
|
|
|
fontSize=16,
|
|
|
|
spaceBefore=20,
|
|
|
|
spaceAfter=10,
|
|
|
|
))
|
|
|
|
stylesheet.add(ParagraphStyle(
|
|
|
|
name='InnerH2Paragraph',
|
|
|
|
parent=stylesheet['InnerH1Paragraph'],
|
|
|
|
fontSize=12,
|
|
|
|
spaceBefore=20,
|
|
|
|
spaceAfter=10,
|
|
|
|
))
|
|
|
|
stylesheet.add(ParagraphStyle(
|
|
|
|
name='InnerH3Paragraph',
|
|
|
|
parent=stylesheet['InnerH2Paragraph'],
|
|
|
|
fontSize=10,
|
|
|
|
spaceBefore=15,
|
|
|
|
spaceAfter=5,
|
|
|
|
))
|
2012-07-10 13:19:12 +02:00
|
|
|
stylesheet.add(ParagraphStyle(
|
|
|
|
name='Small',
|
|
|
|
parent=stylesheet['Normal'],
|
|
|
|
fontSize=8
|
|
|
|
))
|
|
|
|
stylesheet.add(ParagraphStyle(
|
|
|
|
name='Italic',
|
|
|
|
parent=stylesheet['Normal'],
|
|
|
|
fontName='Ubuntu-Italic',
|
|
|
|
spaceAfter=5
|
|
|
|
))
|
|
|
|
stylesheet.add(ParagraphStyle(
|
|
|
|
name='Bold',
|
|
|
|
parent=stylesheet['Normal'],
|
|
|
|
fontName='Ubuntu-Bold',
|
|
|
|
))
|
|
|
|
stylesheet.add(ParagraphStyle(
|
|
|
|
name='Heading1',
|
|
|
|
parent=stylesheet['Bold'],
|
|
|
|
fontSize=24,
|
|
|
|
leading=30,
|
|
|
|
spaceAfter=6,
|
|
|
|
), alias='h1')
|
|
|
|
stylesheet.add(ParagraphStyle(
|
|
|
|
name='Heading2',
|
|
|
|
parent=stylesheet['Bold'],
|
|
|
|
fontSize=14,
|
|
|
|
leading=24,
|
|
|
|
spaceAfter=10,
|
|
|
|
), alias='h2')
|
|
|
|
stylesheet.add(ParagraphStyle(
|
|
|
|
name='Heading3',
|
|
|
|
parent=stylesheet['Bold'],
|
|
|
|
fontSize=12,
|
|
|
|
leading=20,
|
|
|
|
), alias='h3')
|
|
|
|
stylesheet.add(ParagraphStyle(
|
2012-07-10 14:00:51 +02:00
|
|
|
name='Heading4',
|
2012-07-10 13:19:12 +02:00
|
|
|
parent=stylesheet['Bold'],
|
|
|
|
fontSize=10,
|
|
|
|
leading=20,
|
2013-10-23 23:47:25 +02:00
|
|
|
), alias='h4')
|
2012-07-10 13:19:12 +02:00
|
|
|
stylesheet.add(ParagraphStyle(
|
|
|
|
name='Item',
|
|
|
|
parent=stylesheet['Normal'],
|
|
|
|
fontSize=14,
|
|
|
|
leading=14,
|
|
|
|
leftIndent=0,
|
|
|
|
spaceAfter=15,
|
|
|
|
))
|
2012-11-24 14:01:21 +01:00
|
|
|
stylesheet.add(ParagraphStyle(
|
|
|
|
name='Subitem',
|
|
|
|
parent=stylesheet['Normal'],
|
|
|
|
fontSize=10,
|
|
|
|
leading=10,
|
|
|
|
leftIndent=20,
|
|
|
|
spaceAfter=15))
|
|
|
|
stylesheet.add(ParagraphStyle(
|
|
|
|
name='Tablecell',
|
|
|
|
parent=stylesheet['Normal'],
|
|
|
|
fontSize=9))
|
2012-11-26 10:35:29 +01:00
|
|
|
stylesheet.add(ParagraphStyle(name='Signaturefield',
|
|
|
|
parent=stylesheet['Normal'],
|
|
|
|
spaceBefore=15)
|
2011-09-06 22:22:29 +02:00
|
|
|
)
|
|
|
|
|
2011-09-02 17:39:32 +02:00
|
|
|
# Ballot stylesheets
|
2012-11-26 10:35:29 +01:00
|
|
|
stylesheet.add(ParagraphStyle(name='Ballot_title',
|
|
|
|
parent=stylesheet['Bold'],
|
|
|
|
fontSize=12,
|
|
|
|
leading=14,
|
|
|
|
leftIndent=30),
|
2011-09-02 17:39:32 +02:00
|
|
|
)
|
2012-11-26 10:35:29 +01:00
|
|
|
stylesheet.add(ParagraphStyle(name='Ballot_subtitle',
|
|
|
|
parent=stylesheet['Normal'],
|
|
|
|
fontSize=10,
|
|
|
|
leading=12,
|
|
|
|
leftIndent=30,
|
|
|
|
rightIndent=20,
|
|
|
|
spaceAfter=5),
|
2011-09-02 17:39:32 +02:00
|
|
|
)
|
2012-11-26 10:35:29 +01:00
|
|
|
stylesheet.add(ParagraphStyle(name='Ballot_description',
|
|
|
|
parent=stylesheet['Normal'],
|
|
|
|
fontSize=7,
|
|
|
|
leading=10,
|
|
|
|
leftIndent=30),
|
2011-09-02 17:39:32 +02:00
|
|
|
)
|
2012-11-26 10:35:29 +01:00
|
|
|
stylesheet.add(ParagraphStyle(name='Ballot_option',
|
|
|
|
parent=stylesheet['Normal'],
|
|
|
|
fontSize=12,
|
|
|
|
leading=24,
|
|
|
|
leftIndent=30),
|
2011-09-02 17:39:32 +02:00
|
|
|
)
|
2014-03-07 00:17:25 +01:00
|
|
|
stylesheet.add(ParagraphStyle(name='Ballot_option_name_YNA',
|
|
|
|
parent=stylesheet['Ballot_option'],
|
|
|
|
leading=14),
|
|
|
|
)
|
2012-11-26 10:35:29 +01:00
|
|
|
stylesheet.add(ParagraphStyle(name='Ballot_option_name',
|
2014-03-07 00:17:25 +01:00
|
|
|
parent=stylesheet['Ballot_option_name_YNA'],
|
|
|
|
leading=17),
|
2011-09-02 17:39:32 +02:00
|
|
|
)
|
2014-03-07 00:17:25 +01:00
|
|
|
|
|
|
|
stylesheet.add(ParagraphStyle(name='Ballot_option_suffix_YNA',
|
|
|
|
parent=stylesheet['Ballot_option_name_YNA'],
|
2012-11-26 10:35:29 +01:00
|
|
|
fontSize=8,
|
2014-03-07 00:17:25 +01:00
|
|
|
leading=11),
|
2011-09-02 17:39:32 +02:00
|
|
|
)
|
2014-03-07 00:17:25 +01:00
|
|
|
stylesheet.add(ParagraphStyle(name='Ballot_option_suffix',
|
|
|
|
parent=stylesheet['Ballot_option_suffix_YNA'],
|
2012-11-26 10:35:29 +01:00
|
|
|
leading=16,
|
2014-03-07 00:17:25 +01:00
|
|
|
leftIndent=48),
|
|
|
|
)
|
|
|
|
stylesheet.add(ParagraphStyle(name='Ballot_option_circle_YNA',
|
|
|
|
parent=stylesheet['Ballot_option_name_YNA'],
|
|
|
|
leftIndent=48,
|
|
|
|
spaceAfter=18),
|
2011-09-02 17:39:32 +02:00
|
|
|
)
|
2013-03-18 21:17:34 +01:00
|
|
|
# Password paper stylesheets
|
2013-10-23 23:47:25 +02:00
|
|
|
stylesheet.add(ParagraphStyle(name='formfield',
|
2013-03-18 21:17:34 +01:00
|
|
|
parent=stylesheet['Normal'],
|
|
|
|
fontSize=12,
|
2013-10-23 23:47:25 +02:00
|
|
|
leading=18,
|
2013-03-18 21:17:34 +01:00
|
|
|
leftIndent=0),
|
|
|
|
)
|
2013-10-23 23:47:25 +02:00
|
|
|
stylesheet.add(ParagraphStyle(name='formfield_value',
|
2012-11-26 10:35:29 +01:00
|
|
|
parent=stylesheet['Normal'],
|
2013-10-23 23:47:25 +02:00
|
|
|
fontName='Courier',
|
2012-11-26 10:35:29 +01:00
|
|
|
fontSize=12,
|
2013-10-23 23:47:25 +02:00
|
|
|
leading=28,
|
|
|
|
leftIndent=10),
|
|
|
|
)
|
|
|
|
stylesheet.add(ParagraphStyle(name='qrcode_comment',
|
|
|
|
parent=stylesheet['Small'],
|
|
|
|
spaceBefore=6),
|
2012-06-04 10:17:56 +02:00
|
|
|
)
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2011-09-02 15:54:13 +02:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
def firstPage(canvas, doc):
|
|
|
|
canvas.saveState()
|
|
|
|
# page header (with event information)
|
2012-02-21 13:32:39 +01:00
|
|
|
canvas.setFont('Ubuntu', 10)
|
2011-07-31 10:46:29 +02:00
|
|
|
canvas.setFillGray(0.4)
|
2012-06-30 14:50:52 +02:00
|
|
|
|
2015-06-16 18:12:59 +02:00
|
|
|
title_line = u"%s | %s" % (config["general_event_name"],
|
|
|
|
config["general_event_description"])
|
2012-06-30 14:50:52 +02:00
|
|
|
if len(title_line) > 75:
|
|
|
|
title_line = "%s ..." % title_line[:70]
|
2012-07-10 12:11:07 +02:00
|
|
|
canvas.drawString(2.75 * cm, 28 * cm, title_line)
|
2015-06-16 18:12:59 +02:00
|
|
|
if config["general_event_date"] and config["general_event_location"]:
|
2012-07-10 13:19:12 +02:00
|
|
|
canvas.drawString(2.75 * cm, 27.6 * cm, u"%s, %s"
|
2015-06-16 18:12:59 +02:00
|
|
|
% (config["general_event_date"], config["general_event_location"]))
|
2012-07-10 13:19:12 +02:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
# time
|
2012-02-21 13:32:39 +01:00
|
|
|
canvas.setFont('Ubuntu', 7)
|
2012-11-17 21:44:17 +01:00
|
|
|
time = formats.date_format(datetime.now(), 'DATETIME_FORMAT')
|
|
|
|
canvas.drawString(15 * cm, 28 * cm, _("As of: %s") % time)
|
2012-07-10 13:19:12 +02:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
# title
|
2011-09-02 16:34:12 +02:00
|
|
|
if doc.title:
|
2012-02-21 13:32:39 +01:00
|
|
|
canvas.setFont('Ubuntu-Bold', 24)
|
2011-09-02 16:34:12 +02:00
|
|
|
canvas.setFillGray(0)
|
2012-07-10 13:19:12 +02:00
|
|
|
canvas.drawString(2.75 * cm, PAGE_HEIGHT - 108, doc.title)
|
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
# footer (with page number)
|
2012-02-21 13:32:39 +01:00
|
|
|
canvas.setFont('Ubuntu', 8)
|
2011-07-31 10:46:29 +02:00
|
|
|
canvas.setFillGray(0.4)
|
2012-07-10 13:19:12 +02:00
|
|
|
canvas.drawString(10 * cm, 1 * cm, _("Page %s") % doc.page)
|
2011-07-31 10:46:29 +02:00
|
|
|
canvas.restoreState()
|
|
|
|
|
2011-09-06 09:17:39 +02:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
def laterPages(canvas, doc):
|
|
|
|
canvas.saveState()
|
|
|
|
# footer (with page number)
|
2012-02-21 13:32:39 +01:00
|
|
|
canvas.setFont('Ubuntu', 7)
|
2011-07-31 10:46:29 +02:00
|
|
|
canvas.setFillGray(0.4)
|
2012-07-10 13:19:12 +02:00
|
|
|
canvas.drawString(10 * cm, 1 * cm, _("Page %s") % doc.page)
|
2012-02-21 13:32:39 +01:00
|
|
|
canvas.restoreState()
|