diff options
20 files changed, 56 insertions, 92 deletions
| diff --git a/archaeological_context_records/templates/ishtar/sheet_contextrecord_pdf.html b/archaeological_context_records/templates/ishtar/sheet_contextrecord_pdf.html index a0d0affcf..b91500403 100644 --- a/archaeological_context_records/templates/ishtar/sheet_contextrecord_pdf.html +++ b/archaeological_context_records/templates/ishtar/sheet_contextrecord_pdf.html @@ -1,6 +1,5 @@  {% extends "ishtar/sheet_contextrecord.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/archaeological_context_records/templates/ishtar/sheet_contextrecordsource_pdf.html b/archaeological_context_records/templates/ishtar/sheet_contextrecordsource_pdf.html index 38c5d318e..c03b80a53 100644 --- a/archaeological_context_records/templates/ishtar/sheet_contextrecordsource_pdf.html +++ b/archaeological_context_records/templates/ishtar/sheet_contextrecordsource_pdf.html @@ -1,6 +1,5 @@  {% extends "ishtar/sheet_contextrecordsource.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/archaeological_files/templates/ishtar/sheet_file_pdf.html b/archaeological_files/templates/ishtar/sheet_file_pdf.html index eaf2a9436..7335eaec7 100644 --- a/archaeological_files/templates/ishtar/sheet_file_pdf.html +++ b/archaeological_files/templates/ishtar/sheet_file_pdf.html @@ -1,6 +1,5 @@  {% extends "ishtar/sheet_file.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/archaeological_finds/templates/ishtar/sheet_find_pdf.html b/archaeological_finds/templates/ishtar/sheet_find_pdf.html index 262bcdad7..11c39f059 100644 --- a/archaeological_finds/templates/ishtar/sheet_find_pdf.html +++ b/archaeological_finds/templates/ishtar/sheet_find_pdf.html @@ -1,6 +1,5 @@  {% extends "ishtar/sheet_find.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/archaeological_finds/templates/ishtar/sheet_findbasket_pdf.html b/archaeological_finds/templates/ishtar/sheet_findbasket_pdf.html index 2b55f0f76..47a4d2bd8 100644 --- a/archaeological_finds/templates/ishtar/sheet_findbasket_pdf.html +++ b/archaeological_finds/templates/ishtar/sheet_findbasket_pdf.html @@ -1,6 +1,5 @@  {% extends "ishtar/sheet_findbasket.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/archaeological_finds/templates/ishtar/sheet_findsource_pdf.html b/archaeological_finds/templates/ishtar/sheet_findsource_pdf.html index 26ef9f2d7..7ca3bd3c1 100644 --- a/archaeological_finds/templates/ishtar/sheet_findsource_pdf.html +++ b/archaeological_finds/templates/ishtar/sheet_findsource_pdf.html @@ -1,6 +1,5 @@  {% extends "ishtar/sheet_findsource.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/archaeological_finds/templates/ishtar/sheet_treatment_pdf.html b/archaeological_finds/templates/ishtar/sheet_treatment_pdf.html index 08df52e97..ccd860ec9 100644 --- a/archaeological_finds/templates/ishtar/sheet_treatment_pdf.html +++ b/archaeological_finds/templates/ishtar/sheet_treatment_pdf.html @@ -1,6 +1,5 @@  {% extends "ishtar/sheet_treatment.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 @@  {% endblock %}  {%block head_sheet%}{%endblock%}  {%block main_foot%} -<div id="pdffooter"> -    – <pdf:pagenumber/> – -</div>  </body>  </html>  {%endblock%} diff --git a/archaeological_finds/templates/ishtar/sheet_treatmentfile_pdf.html b/archaeological_finds/templates/ishtar/sheet_treatmentfile_pdf.html index be64ff7eb..c216556b3 100644 --- a/archaeological_finds/templates/ishtar/sheet_treatmentfile_pdf.html +++ b/archaeological_finds/templates/ishtar/sheet_treatmentfile_pdf.html @@ -1,6 +1,5 @@  {% extends "ishtar/sheet_treatmentfile.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 @@  {% endblock %}  {%block head_sheet%}{%endblock%}  {%block main_foot%} -<div id="pdffooter"> -    – <pdf:pagenumber/> – -</div>  </body>  </html>  {%endblock%} diff --git a/archaeological_finds/templates/ishtar/sheet_treatmentfilesource_pdf.html b/archaeological_finds/templates/ishtar/sheet_treatmentfilesource_pdf.html index d0a0ec8e7..2ef4d63b5 100644 --- a/archaeological_finds/templates/ishtar/sheet_treatmentfilesource_pdf.html +++ b/archaeological_finds/templates/ishtar/sheet_treatmentfilesource_pdf.html @@ -1,6 +1,5 @@  {% extends "ishtar/sheet_treatmentfilesource.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/archaeological_finds/templates/ishtar/sheet_treatmentsource_pdf.html b/archaeological_finds/templates/ishtar/sheet_treatmentsource_pdf.html index c38764559..4b7218a14 100644 --- a/archaeological_finds/templates/ishtar/sheet_treatmentsource_pdf.html +++ b/archaeological_finds/templates/ishtar/sheet_treatmentsource_pdf.html @@ -1,6 +1,5 @@  {% extends "ishtar/sheet_treatmentsource.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/archaeological_operations/templates/ishtar/sheet_administrativeact_pdf.html b/archaeological_operations/templates/ishtar/sheet_administrativeact_pdf.html index b6d257cb0..be3e24428 100644 --- a/archaeological_operations/templates/ishtar/sheet_administrativeact_pdf.html +++ b/archaeological_operations/templates/ishtar/sheet_administrativeact_pdf.html @@ -1,6 +1,5 @@  {% extends "ishtar/sheet_administrativeact.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/archaeological_operations/templates/ishtar/sheet_operation_pdf.html b/archaeological_operations/templates/ishtar/sheet_operation_pdf.html index dc3c8b46f..7d86bd924 100644 --- a/archaeological_operations/templates/ishtar/sheet_operation_pdf.html +++ b/archaeological_operations/templates/ishtar/sheet_operation_pdf.html @@ -1,6 +1,5 @@  {% extends "ishtar/sheet_operation.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/archaeological_operations/templates/ishtar/sheet_operationsource_pdf.html b/archaeological_operations/templates/ishtar/sheet_operationsource_pdf.html index 1b2cd9ff3..68eb7aa2d 100644 --- a/archaeological_operations/templates/ishtar/sheet_operationsource_pdf.html +++ b/archaeological_operations/templates/ishtar/sheet_operationsource_pdf.html @@ -1,6 +1,5 @@  {% extends "ishtar/sheet_operationsource.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/archaeological_warehouse/templates/ishtar/sheet_container_pdf.html b/archaeological_warehouse/templates/ishtar/sheet_container_pdf.html index 5e4947cfa..ba0e3164c 100644 --- a/archaeological_warehouse/templates/ishtar/sheet_container_pdf.html +++ b/archaeological_warehouse/templates/ishtar/sheet_container_pdf.html @@ -1,6 +1,5 @@  {% extends "ishtar/sheet_container.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/archaeological_warehouse/templates/ishtar/sheet_warehouse_pdf.html b/archaeological_warehouse/templates/ishtar/sheet_warehouse_pdf.html index 260834ac6..d95efe58f 100644 --- a/archaeological_warehouse/templates/ishtar/sheet_warehouse_pdf.html +++ b/archaeological_warehouse/templates/ishtar/sheet_warehouse_pdf.html @@ -1,6 +1,5 @@  {% extends "ishtar/sheet_warehouse.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/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) diff --git a/requirements.txt b/requirements.txt index 2b41343a2..feecbe8e1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,15 +2,15 @@ psycopg2==2.5.4  django-registration==2.2  django==1.11  Pillow==3.4.2 -pisa==3.0.33 -reportlab==3.1.8 +WeasyPrint==0.41 +html5lib==0.999999999 +  dbf==0.96.003  python-memcached==1.57  unicodecsv==0.14.1  pytidylib==0.2.1  lxml==3.4.0 -html5lib==0.999  django-extra-views==0.2.4  beautifulsoup4==4.3.2 | 
