From e2388422822ba47b4ef091215ca8b4e3c12cdf19 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sat, 26 Feb 2011 00:24:48 +0100 Subject: Process differently to generate ODT file (refs #227). Specific CSS for export. --- ishtar/furnitures/views.py | 28 ++++++++++++---------- ishtar/templates/sheet.html | 1 + ishtar/templates/sheet_file.html | 50 ++++++++++++++++++++-------------------- static/media/style.css | 9 ++++---- static/media/style_basic.css | 45 ++++++++++++++++++++++++++++++++++++ 5 files changed, 91 insertions(+), 42 deletions(-) create mode 100644 static/media/style_basic.css diff --git a/ishtar/furnitures/views.py b/ishtar/furnitures/views.py index b6e6f91eb..e874e8cc2 100644 --- a/ishtar/furnitures/views.py +++ b/ishtar/furnitures/views.py @@ -21,6 +21,8 @@ Furnitures views """ +import tidy +import re import csv import json import datetime @@ -251,15 +253,19 @@ def show_item(model, name): tpl = loader.get_template('sheet_%s.html' % name) content = tpl.render(context_instance) try: - ht, odt = NamedTemporaryFile(), NamedTemporaryFile() - ht.write(content.encode('utf-8')) + tidy_options = dict(output_xhtml=1, add_xml_decl=1, indent=1, + tidy_mark=0, output_encoding='utf8', doctype='auto', + wrap=0, char_encoding='utf8') + html = str(tidy.parseString(content.encode('utf-8'), + **tidy_options)) + html = html.replace(" ", " ") + html = re.sub(']*)>\n', '', html) + + odt = NamedTemporaryFile() options = optparse.Values() - options.input = ht.name - options.output = odt.name - options.template = settings.ODT_TEMPLATE options.with_network = True - for k, v in (('input', ht.name), - ('output', None), + for k, v in (('input', ''), + ('output', odt.name), ('template', settings.ODT_TEMPLATE), ('with_network', True), ('top_header_level', 1), @@ -271,19 +277,17 @@ def show_item(model, name): ('htmlid', None), ('url', "#")): setattr(options, k, v) - htmlfile = xhtml2odt.HTMLFile(options) - htmlfile.read() odtfile = xhtml2odt.ODTFile(options) odtfile.open() - odtfile.import_xhtml(htmlfile.html) - hop = odtfile.save() + odtfile.import_xhtml(html) + odtfile = odtfile.save() except xhtml2odt.ODTExportError, ex: return HttpResponse(content, content_type="application/xhtml") response = HttpResponse( mimetype='application/vnd.oasis.opendocument.text') response['Content-Disposition'] = 'attachment; filename=%s.odt' % \ filename - response.write(hop) + response.write(odtfile) return response elif doc_type == 'pdf': tpl = loader.get_template('sheet_%s.html' % name) diff --git a/ishtar/templates/sheet.html b/ishtar/templates/sheet.html index a93b193e0..c157b61a0 100644 --- a/ishtar/templates/sheet.html +++ b/ishtar/templates/sheet.html @@ -8,6 +8,7 @@ {% block title %}Ishtar{% if APP_NAME %} - {{APP_NAME}}{%endif%}{% endblock %} + {% endblock %} diff --git a/ishtar/templates/sheet_file.html b/ishtar/templates/sheet_file.html index 4f1ebbc3d..865acca41 100644 --- a/ishtar/templates/sheet_file.html +++ b/ishtar/templates/sheet_file.html @@ -3,51 +3,51 @@ {% block content %}

{% trans "General"%}

-

{{ item.year }}

-

{{ item.numeric_reference }}

+

{{ item.year }}

+

{{ item.numeric_reference }}

-

{{ item.internal_reference }}

+

{{ item.internal_reference }}

-

{{ item.history.all.0.history_date }}

-{% if item.reception_date %}

{{ item.reception_date }}

{% endif %} -

{{ item.creation_date }}

+

{{ item.history.all.0.history_date }}

+{% if item.reception_date %}

{{ item.reception_date }}

{% endif %} +

{{ item.creation_date }}

{% comment %} {% if item.deadline_date and not item.acts %} -

{% item.deadline_date %}

+

{% item.deadline_date %}

{% endif %} {% endcomment %} -

{{ item.in_charge.full_label }}

-

{% if item.is_active %}{%trans "Active file"%}

+

{{ item.in_charge.full_label }}

+

{% if item.is_active %}{%trans "Active file"%}

{% else %}{%trans "Closed file"%}

-

{{ item.closing.date }} {%trans "by" %} {{ item.closing.user }}

+

{{ item.closing.date }} {%trans "by" %} {{ item.closing.user }}

{% endif %} -

{{ item.file_type }}

+

{{ item.file_type }}

-{% if item.related_file %}

{{ item.related_file }}

{% endif %} -{% if item.comment %}

{{ item.comment }}

{%endif%} +{% if item.related_file %}

{{ item.related_file }}

{% endif %} +{% if item.comment %}

{{ item.comment }}

{%endif%}

{% trans "Localisation"%}

-

{{ item.towns.all|join:", " }}

+

{{ item.towns.all|join:", " }}

-

{{ item.address }}

-{% if item.address_complement %}

{{ item.address_complement }}

{%endif%} -{% if item.postal_code %}

{{ item.postal_code }}

{%endif%} +

{{ item.address }}

+{% if item.address_complement %}

{{ item.address_complement }}

{%endif%} +{% if item.postal_code %}

{{ item.postal_code }}

{%endif%} -

{{ item.total_surface }} m2 ({{ item.total_surface_ha }} ha)

+

{{ item.total_surface }} m2 ({{ item.total_surface_ha }} ha)

{% if item.is_preventive %}

{% trans "Preventive archaelogical file"%}

-

{{ item.total_developed_surface }} m2 ({{ item.total_developed_surface_ha }} ha)

-

{{ item.saisine_type }}

-{% if item.town_planning_service %}

{{ item.town_planning_service }}

{% endif %} -{% if item.permit_type %}

{{ item.permit_type }}

{% endif %} -{% if item.permit_reference %}

{{ item.permit_reference }}

{% endif %} -{% if item.general_contractor.attached_to %}

{{ item.general_contractor.attached_to }}

{% endif %} -{% if item.general_contractor %}

{{ item.general_contractor.full_label }}

{% endif %} +

{{ item.total_developed_surface }} m2 ({{ item.total_developed_surface_ha }} ha)

+

{{ item.saisine_type }}

+{% if item.town_planning_service %}

{{ item.town_planning_service }}

{% endif %} +{% if item.permit_type %}

{{ item.permit_type }}

{% endif %} +{% if item.permit_reference %}

{{ item.permit_reference }}

{% endif %} +{% if item.general_contractor.attached_to %}

{{ item.general_contractor.attached_to }}

{% endif %} +{% if item.general_contractor %}

{{ item.general_contractor.full_label }}

{% endif %} {% endif %} diff --git a/static/media/style.css b/static/media/style.css index 9f048d59a..27a31c08b 100644 --- a/static/media/style.css +++ b/static/media/style.css @@ -247,7 +247,6 @@ table.confirm tr.spacer td:last-child{ #window{ width:760px; - position: absolute; position:fixed; height:90%; background: #FFF; @@ -292,8 +291,8 @@ table.confirm tr.spacer td:last-child{ } #window table td.no_items{ -text-align:center; -font-style:italic; + text-align:center; + font-style:italic; } #window .sheet{ @@ -312,8 +311,8 @@ font-style:italic; } #window .tool{ -text-align:center; -font-style:italic; + text-align:center; + font-style:italic; } #window .body{ diff --git a/static/media/style_basic.css b/static/media/style_basic.css new file mode 100644 index 000000000..ec96ecfce --- /dev/null +++ b/static/media/style_basic.css @@ -0,0 +1,45 @@ +#window{ + width:100%; + position:relative; + display:block; + height:100%; + left:0; + margin:0; +} + +#window table{ + font-size:1em; + margin:0; + width:100%; + border-collapse:collapse; +} + +#window .head{ + display:none; +} + +#window .tool{ + display:none; +} + +#window .body{ + position:relative; + padding:0; + top:0; + bottom:0; + width:100%; +} + +#window label{ + display:inline; + font-weight:bold; +} + +#window span.value{ + display:inline; +} + +#window p{ + margin:0.3em; +} + -- cgit v1.2.3