summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ishtar_common/menus.py1
-rw-r--r--ishtar_common/templates/ishtar/blocks/window_image.html84
-rw-r--r--ishtar_common/templates/ishtar/blocks/window_image_detail.html74
-rw-r--r--ishtar_common/templates/ishtar/blocks/window_image_odt.html9
-rw-r--r--ishtar_common/templates/ishtar/sheet.html26
-rw-r--r--ishtar_common/views_item.py59
-rw-r--r--setup.py2
7 files changed, 133 insertions, 122 deletions
diff --git a/ishtar_common/menus.py b/ishtar_common/menus.py
index 6d51323ab..43415793f 100644
--- a/ishtar_common/menus.py
+++ b/ishtar_common/menus.py
@@ -62,6 +62,7 @@ class Menu:
self.user = user
self.initialized = False
self.items = {}
+ self.childs = []
self.current_action = current_action
self.current_section = None
self.current_url = None
diff --git a/ishtar_common/templates/ishtar/blocks/window_image.html b/ishtar_common/templates/ishtar/blocks/window_image.html
index aa43e1ca5..ab1013df9 100644
--- a/ishtar_common/templates/ishtar/blocks/window_image.html
+++ b/ishtar_common/templates/ishtar/blocks/window_image.html
@@ -1,81 +1,12 @@
{% load i18n %}{% if item.images.count %}
+{% if output == "ODT" or output == "PDF"%}
+{% include "ishtar/blocks/window_image_odt.html" %}
+{% else %}
<div class="lightgallery-captions">
{% for image in item.images.all %}
<div id="lightgallery-{{window_id}}-caption-{{forloop.counter0}}">
<span class="close">&times</span>
- {% if image.title %}<h3>{{image.title}}</h3>{% endif %}
- {% if image.description %}<p class="raw-description">
- {{image.description}}
- </p>{% endif %}
- {% if image.licences.count %}
- <div class="row">
- <div class="col-2">
- <strong>{% trans "Licenses" %}</strong>
- </div>
- <div class="col-10">
- {% for license in image.licenses.all %}
- {% if not forloop.first %} ; {% endif %}{% if license.url %}<a href="{{license.url}}">{% endif %}
- {{license}}
- {% if license.url %}</a>{% endif %}
- {% endfor %}
- </div>
- </div>
- {% endif %}
- {% if image.authors.count or image.authors_raw %}
- <div class="row">
- <div class="col-2">
- <strong>{% trans "Authors" %}</strong>
- </div>
- <div class="col-10">
- {% for author in image.authors.all %}
- {% if not forloop.first %} ; {% endif %}{{author}}{% endfor %}
- {% if image.authors_raw %}
- {% if image.authors.count %} ; {% endif %}
- {{image.authors_raw}}
- {% endif %}
- </div>
- </div>
- {% endif %}
- {% if image.image_type %}
- <div class="row">
- <div class="col-2">
- <strong>{% trans "Type" %}</strong>
- </div>
- <div class="col-10">
- {{image.image_type}}
- </div>
- </div>
- {% endif %}
- {% if image.reference %}
- <div class="row">
- <div class="col-2">
- <strong>{% trans "Ref." %}</strong>
- </div>
- <div class="col-10">
- {{image.reference}}
- </div>
- </div>
- {% endif %}
- {% if image.internal_reference %}
- <div class="row">
- <div class="col-2">
- <strong>{% trans "Internal ref." %}</strong>
- </div>
- <div class="col-10">
- {{image.internal_reference}}
- </div>
- </div>
- {% endif %}
- {% if image.creation_date %}
- <div class="row">
- <div class="col-2">
- <strong>{% trans "Creation date" %}</strong>
- </div>
- <div class="col-10">
- {{image.creation_date}}
- </div>
- </div>
- {% endif %}
+ {% include "ishtar/blocks/window_image_detail.html" %}
<a href="{% url 'edit-document' image.pk %}">
{% trans "Modify" %} &nbsp;<i class="fa fa-pencil"></i>
</a>
@@ -84,10 +15,11 @@
</div>
<div id="lightgallery-{{window_id}}">
{% for image in item.images.all %}
- {% if output != "ODT" %}<a data-sub-html="#lightgallery-{{window_id}}-caption-{{forloop.counter0}}" href="{{image.image.url}}"{% if not forloop.first %}
- class="lightgallery-subimage"{% endif %}>{% endif %}
+ <a data-sub-html="#lightgallery-{{window_id}}-caption-{{forloop.counter0}}" href="{{image.image.url}}"{% if not forloop.first %}
+ class="lightgallery-subimage"{% endif %}>
<img{% if forloop.first %} class='card-img-top'{% endif %} src="{{BASE_URL}}{{image.thumbnail.url}}">
- {% if output != "ODT" %}</a>{% endif %}
+ </a>
{% endfor %}
</div>
{% endif%}
+{% endif%}
diff --git a/ishtar_common/templates/ishtar/blocks/window_image_detail.html b/ishtar_common/templates/ishtar/blocks/window_image_detail.html
new file mode 100644
index 000000000..c64d72ac2
--- /dev/null
+++ b/ishtar_common/templates/ishtar/blocks/window_image_detail.html
@@ -0,0 +1,74 @@
+{% load i18n %}
+ {% if image.title %}<h3>{{image.title}}</h3>{% endif %}
+ {% if image.description %}<p class="raw-description">
+ {{image.description}}
+ </p>{% endif %}
+ {% if image.licences.count %}
+ <div class="row">
+ <div class="col-2">
+ <strong>{% trans "Licenses" %}</strong>
+ </div>
+ <div class="col-10">
+ {% for license in image.licenses.all %}
+ {% if not forloop.first %} ; {% endif %}{% if license.url %}<a href="{{license.url}}">{% endif %}
+ {{license}}
+ {% if license.url %}</a>{% endif %}
+ {% endfor %}
+ </div>
+ </div>
+ {% endif %}
+ {% if image.authors.count or image.authors_raw %}
+ <div class="row">
+ <div class="col-2">
+ <strong>{% trans "Authors" %}</strong>
+ </div>
+ <div class="col-10">
+ {% for author in image.authors.all %}
+ {% if not forloop.first %} ; {% endif %}{{author}}{% endfor %}
+ {% if image.authors_raw %}
+ {% if image.authors.count %} ; {% endif %}
+ {{image.authors_raw}}
+ {% endif %}
+ </div>
+ </div>
+ {% endif %}
+ {% if image.image_type %}
+ <div class="row">
+ <div class="col-2">
+ <strong>{% trans "Type" %}</strong>
+ </div>
+ <div class="col-10">
+ {{image.image_type}}
+ </div>
+ </div>
+ {% endif %}
+ {% if image.reference %}
+ <div class="row">
+ <div class="col-2">
+ <strong>{% trans "Ref." %}</strong>
+ </div>
+ <div class="col-10">
+ {{image.reference}}
+ </div>
+ </div>
+ {% endif %}
+ {% if image.internal_reference %}
+ <div class="row">
+ <div class="col-2">
+ <strong>{% trans "Internal ref." %}</strong>
+ </div>
+ <div class="col-10">
+ {{image.internal_reference}}
+ </div>
+ </div>
+ {% endif %}
+ {% if image.creation_date %}
+ <div class="row">
+ <div class="col-2">
+ <strong>{% trans "Creation date" %}</strong>
+ </div>
+ <div class="col-10">
+ {{image.creation_date}}
+ </div>
+ </div>
+ {% endif %}
diff --git a/ishtar_common/templates/ishtar/blocks/window_image_odt.html b/ishtar_common/templates/ishtar/blocks/window_image_odt.html
new file mode 100644
index 000000000..9c9383cdd
--- /dev/null
+++ b/ishtar_common/templates/ishtar/blocks/window_image_odt.html
@@ -0,0 +1,9 @@
+{% load i18n %}
+<div class="lightgallery-captions">
+ {% for image in item.images.all %}
+ <div id="lightgallery-{{window_id}}-caption-{{forloop.counter0}}">
+ <img src="{{BASE_URL}}{{image.thumbnail.url}}">
+ {% include "ishtar/blocks/window_image_detail.html" %}
+ </div>
+ {% endfor %}
+</div>
diff --git a/ishtar_common/templates/ishtar/sheet.html b/ishtar_common/templates/ishtar/sheet.html
index 54a2f767d..e937f1474 100644
--- a/ishtar_common/templates/ishtar/sheet.html
+++ b/ishtar_common/templates/ishtar/sheet.html
@@ -13,13 +13,23 @@
<div class="card-header" data-sheet-id="{{sheet_id}}" role="tab" id='head-{{window_id}}'>
<div class="row">
<div class="col-9">
+ {% if output != "ODT" and output != "PDF"%}
<h5 class="mb-0">
- <a class="card-label" data-toggle="collapse" href="#collapse-{{window_id}}" aria-expanded="true"
+ <a class="card-label" data-toggle="collapse"
+ href="#collapse-{{window_id}}" aria-expanded="true"
aria-controls="collapse-{{window_id}}">
+ {% else %}
+ <h2>
+ {% endif %}
{% block head_title %}{% endblock %}
+ {% if output == "ODT" or output == "PDF"%}
+ </h2>
+ {% else %}
</a>
</h5>
+ {% endif %}
</div>
+ {% if output != "ODT" and output != "PDF"%}
<div class='col-2 text-center'>
<a href='#' class='previous_page'>
<span class="fa-stack">
@@ -42,24 +52,19 @@
<i class="fa fa-times fa-stack-1x fa-inverse"></i>
</span>
</a>
- {% comment %}
- <a href='#' onclick='closeAllWindows();' title="{% trans "Close all windows" %}">
- <span class="fa-stack">
- <i class="fa fa-files-o fa-stack-2x"></i>
- <i class="fa fa-circle fa-stack-15x"></i>
- <i class="fa fa-times fa-stack-1x fa-inverse"></i>
- </span>
- </a>
- {% endcomment %}
</div>
+ {% endif %}
</div>
{% block header_title %}{% endblock %}
</div>
<div id="collapse-{{window_id}}" class="collapse show" role="tabpanel"
aria-labelledby="heading-{{window_id}}" data-parent="#window">
+ {% if output != "ODT" and output != "PDF"%}
{% block toolbar %}{% endblock %}
+ {% endif %}
<div class="card-body">
+ {% if output != "ODT" and output != "PDF"%}
{% block head_sheet %}
<script type="text/javascript">
var last_window='{{window_id}}';
@@ -97,6 +102,7 @@
});
</script>
{% endblock %}
+ {% endif %}
<div class="body">
{% block content %}
{% endblock %}
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index b286ab3bf..513035903 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -1,13 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+from copy import copy, deepcopy
import csv
import datetime
import json
import logging
-import optparse
import re
-from copy import copy, deepcopy
+import subprocess
from tempfile import NamedTemporaryFile
from django.conf import settings
@@ -26,7 +26,6 @@ from tidylib import tidy_document as tidy
from unidecode import unidecode
from weasyprint import HTML, CSS
from weasyprint.fonts import FontConfiguration
-from xhtml2odt import xhtml2odt
from ishtar_common.utils import check_model_access_control, CSV_OPTIONS, \
get_all_field_names
@@ -180,41 +179,31 @@ def show_item(model, name, extra_dct=None):
tpl = loader.get_template('ishtar/sheet_%s.html' % name)
context_instance['output'] = 'ODT'
content = tpl.render(context_instance, request)
+ tidy_options = {'output-xhtml': 1, 'indent': 1,
+ 'tidy-mark': 0, 'doctype': 'auto',
+ 'add-xml-decl': 1, 'wrap': 1}
+ html, errors = tidy(content, options=tidy_options)
+ html = html.encode('utf-8').replace("&nbsp;", "&#160;")
+ html = re.sub('<pre([^>]*)>\n', '<pre\\1>', html)
+
+ odt = NamedTemporaryFile()
+ html_source = NamedTemporaryFile()
+ with open(html_source.name, 'w') as html_file:
+ html_file.write(html)
+
+ pandoc_args = ["pandoc", "-f", "html", "-t", "odt",
+ "-o", odt.name, html_source.name]
try:
- tidy_options = {'output-xhtml': 1, 'indent': 1,
- 'tidy-mark': 0, 'doctype': 'auto',
- 'add-xml-decl': 1, 'wrap': 1}
- html, errors = tidy(content, options=tidy_options)
- html = html.encode('utf-8').replace("&nbsp;", "&#160;")
- html = re.sub('<pre([^>]*)>\n', '<pre\\1>', html)
-
- odt = NamedTemporaryFile()
- options = optparse.Values()
- options.with_network = True
- for k, v in (('input', ''),
- ('output', odt.name),
- ('template', settings.ODT_TEMPLATE),
- ('with_network', True),
- ('top_header_level', 1),
- ('img_width', '8cm'),
- ('img_height', '6cm'),
- ('verbose', False),
- ('replace_keyword', 'ODT-INSERT'),
- ('cut_start', 'ODT-CUT-START'),
- ('htmlid', None),
- ('url', "#")):
- setattr(options, k, v)
- odtfile = xhtml2odt.ODTFile(options)
- odtfile.open()
- odtfile.import_xhtml(html)
- odtfile = odtfile.save()
- except xhtml2odt.ODTExportError:
- return HttpResponse(content, content_type="application/xhtml")
+ subprocess.check_call(pandoc_args)
+ except subprocess.CalledProcessError:
+ return HttpResponse(content,
+ content_type="application/xhtml")
response = HttpResponse(
content_type='application/vnd.oasis.opendocument.text')
- response['Content-Disposition'] = 'attachment; filename=%s.odt' % \
- filename
- response.write(odtfile)
+ response['Content-Disposition'] = \
+ 'attachment; filename={}.odt'.format(filename)
+ with open(odt.name, 'r') as odt_file:
+ response.write(odt_file.read())
return response
elif doc_type == 'pdf':
tpl = loader.get_template('ishtar/sheet_%s_pdf.html' % name)
diff --git a/setup.py b/setup.py
index fc0a1a23f..46a8df3ab 100644
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,7 @@ setup(
packages=[
'archaeological_finds', 'example_project',
'archaeological_warehouse', 'archaeological_files_pdl',
- 'archaeological_files', 'xhtml2odt', 'simple_history', 'ishtar_common',
+ 'archaeological_files', 'simple_history', 'ishtar_common',
'archaeological_operations', 'archaeological_context_records',
'ishtar_pdl'],
include_package_data=True,