diff options
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/static/media/style_basic.css | 35 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/sheet_organization_pdf.html | 4 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/sheet_person_pdf.html | 4 | ||||
-rw-r--r-- | ishtar_common/views.py | 39 |
4 files changed, 53 insertions, 29 deletions
diff --git a/ishtar_common/static/media/style_basic.css b/ishtar_common/static/media/style_basic.css index 1d92928dc..d0f5bbe4a 100644 --- a/ishtar_common/static/media/style_basic.css +++ b/ishtar_common/static/media/style_basic.css @@ -1,7 +1,8 @@ @page { size: a4 portrait; - margin: 2.5cm 1cm 2.5cm 1cm; + margin: 2cm 1cm 2.5cm 1cm; background-image: url("images/ishtar-bg.jpg"); + background-repeat: no-repeat; @frame footer { -pdf-frame-content: pdffooter; bottom: 1cm; @@ -16,6 +17,9 @@ margin-right: 1cm; height: 1.5cm; } + @bottom-center { + content: counter(page) "/" counter(pages); + } } label{ @@ -36,6 +40,13 @@ caption, h3{ font-size:1.5em; } +a img { + display: block; + margin-left: auto; + margin-right: auto; + padding:0.5em; +} + th{ text-align:center; border-bottom:2px solid #922; @@ -72,10 +83,21 @@ td{ display:none; } +caption, hr, .tool-left, .tool-right, .display_details, .display_details_inline{ + display: None; + color: transparent; + background-color: transparent; + border-color: transparent; +} + p{ margin:0.2em; } +td{ + background-color: #ddd; +} + #pdffooter, #pdfheader{ text-align:center; } @@ -84,8 +106,15 @@ p{ font-weight:bold; width:100%; border-bottom:1px solid #922; + position: fixed; + top: -0.5cm; } -.display_details, .display_details_inline{ - display: none; +.window-refs{ + text-align:center; + padding:0; + margin:0; + font-size: 0.9em; + width:100%; + display:block; } diff --git a/ishtar_common/templates/ishtar/sheet_organization_pdf.html b/ishtar_common/templates/ishtar/sheet_organization_pdf.html index 887c7ccb2..2276aa4d1 100644 --- a/ishtar_common/templates/ishtar/sheet_organization_pdf.html +++ b/ishtar_common/templates/ishtar/sheet_organization_pdf.html @@ -1,6 +1,5 @@ {% extends "ishtar/sheet_organization.html" %} {% block header %} -<link rel="stylesheet" href="{{STATIC_URL}}/media/style_basic.css?ver={{VERSION}}" /> {% endblock %} {% block main_head %} {{ block.super }} @@ -10,9 +9,6 @@ Ishtar – {{APP_NAME}} – {{item}} {% endblock %} {%block head_sheet%}{%endblock%} {%block main_foot%} -<div id="pdffooter"> -– <pdf:pagenumber/> – -</div> </body> </html> {%endblock%} diff --git a/ishtar_common/templates/ishtar/sheet_person_pdf.html b/ishtar_common/templates/ishtar/sheet_person_pdf.html index 199892d2f..9dd9e4c50 100644 --- a/ishtar_common/templates/ishtar/sheet_person_pdf.html +++ b/ishtar_common/templates/ishtar/sheet_person_pdf.html @@ -1,6 +1,5 @@ {% extends "ishtar/sheet_person.html" %} {% block header %} -<link rel="stylesheet" href="{{STATIC_URL}}/media/style_basic.css?ver={{VERSION}}" /> {% endblock %} {% block main_head %} {{ block.super }} @@ -10,9 +9,6 @@ Ishtar – {{APP_NAME}} – {{item}} {% endblock %} {%block head_sheet%}{%endblock%} {%block main_foot%} -<div id="pdffooter"> -– <pdf:pagenumber/> – -</div> </body> </html> {%endblock%} diff --git a/ishtar_common/views.py b/ishtar_common/views.py index b8350c62a..8d475aff5 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (C) 2010-2016 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2010-2017 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -21,13 +21,7 @@ from tidylib import tidy_document as tidy from copy import copy, deepcopy import csv -import cStringIO as StringIO import datetime - -import reportlab -reportlab.Version = "2.2" # stupid hack for an old library... -import ho.pisa as pisa - import json import logging from markdown import markdown @@ -35,6 +29,8 @@ import optparse import re from tempfile import NamedTemporaryFile import unicodedata +from weasyprint import HTML, CSS +from weasyprint.fonts import FontConfiguration from extra_views import ModelFormSetView @@ -42,6 +38,7 @@ from django.conf import settings from django.contrib.auth import logout from django.contrib.auth.decorators import login_required from django.contrib.postgres.search import SearchQuery +from django.contrib.staticfiles.templatetags.staticfiles import static from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse, NoReverseMatch from django.db.models import Q, ImageField @@ -1333,19 +1330,25 @@ def show_item(model, name, extra_dct=None): elif doc_type == 'pdf': tpl = loader.get_template('ishtar/sheet_%s_pdf.html' % name) context_instance['output'] = 'PDF' - content = tpl.render(context_instance, request) - result = StringIO.StringIO() - html = content.encode('utf-8') - html = html.replace("<table", "<pdf:nextpage/><table repeat='1'") - pdf = pisa.pisaDocument(StringIO.StringIO(html), result, - encoding='utf-8') - response = HttpResponse(result.getvalue(), - content_type='application/pdf') + html = tpl.render(context_instance, request) + font_config = FontConfiguration() + css = CSS(string=''' + @font-face { + font-family: Gentium; + src: url(%s); + } + body{ + font-family: Gentium + } + ''' % (static("gentium/GentiumPlus-R.ttf"))) + css2 = CSS(filename=settings.STATIC_ROOT + '/media/style_basic.css') + pdf = HTML(string=html, base_url=request.build_absolute_uri() + ).write_pdf(stylesheets=[css, css2], + font_config=font_config) + response = HttpResponse(pdf, content_type='application/pdf') response['Content-Disposition'] = 'attachment; filename=%s.pdf' % \ filename - if not pdf.err: - return response - return HttpResponse(content, content_type="application/xhtml") + return response else: tpl = loader.get_template('ishtar/sheet_%s_window.html' % name) content = tpl.render(context_instance, request) |