summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2011-02-26 00:24:48 +0100
committerÉtienne Loks <etienne.loks@peacefrogs.net>2011-02-26 00:24:48 +0100
commit05b4f9af9d26553974088f31fbcd66b5e535c7ba (patch)
treec7a7a964b6754231f4ce28962dda5f6e1734ab48
parent76cd8b6319c095866e0f494a57f2e58a716561eb (diff)
downloadIshtar-05b4f9af9d26553974088f31fbcd66b5e535c7ba.tar.bz2
Ishtar-05b4f9af9d26553974088f31fbcd66b5e535c7ba.zip
Process differently to generate ODT file (refs #227). Specific CSS for export.
-rw-r--r--ishtar/furnitures/views.py28
-rw-r--r--ishtar/templates/sheet.html1
-rw-r--r--ishtar/templates/sheet_file.html50
-rw-r--r--static/media/style.css9
-rw-r--r--static/media/style_basic.css45
5 files changed, 91 insertions, 42 deletions
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("&nbsp;", "&#160;")
+ html = re.sub('<pre([^>]*)>\n', '<pre\\1>', 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 @@
<title>{% block title %}Ishtar{% if APP_NAME %} - {{APP_NAME}}{%endif%}{% endblock %}
</title>
<link rel="stylesheet" href="{{MEDIA_URL}}/media/style.css" />
+ <link rel="stylesheet" href="{{MEDIA_URL}}/media/style_basic.css" />
</head>
<body>
{% 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 %}
<div class='tool'>{%trans "Export as:"%} <a href='{% url show-file item.pk "odt" %}'>{%trans "OpenOffice.org file"%} (experimental)</a>, <a href='{% url show-file item.pk "pdf" %}'>{%trans "PDF file"%} (experimental)</a></div>
<h3>{% trans "General"%}</h3>
-<p><label>{%trans "Year:"%}</label><span class='value'>{{ item.year }}</span></p>
-<p><label>{%trans "Numerical reference:"%}</label><span class='value'>{{ item.numeric_reference }}</span></p>
+<p><label>{%trans "Year:"%}</label> <span class='value'>{{ item.year }}</span></p>
+<p><label>{%trans "Numerical reference:"%}</label> <span class='value'>{{ item.numeric_reference }}</span></p>
-<p><label>{%trans "File's name:"%}</label><span class='value'>{{ item.internal_reference }}</span></p>
+<p><label>{%trans "File's name:"%}</label> <span class='value'>{{ item.internal_reference }}</span></p>
-<p><label>{%trans "Edition date:"%}</label><span class='value'>{{ item.history.all.0.history_date }}</span></p> <!-- date = now -->
-{% if item.reception_date %}<p><label>{%trans "Reception date:"%}</label><span class='value'>{{ item.reception_date }}</span></p>{% endif %}
-<p><label>{%trans "Creation date:"%}</label><span class='value'>{{ item.creation_date }}</span></p>
+<p><label>{%trans "Edition date:"%}</label> <span class='value'>{{ item.history.all.0.history_date }}</span></p> <!-- date = now -->
+{% if item.reception_date %}<p><label>{%trans "Reception date:"%}</label> <span class='value'>{{ item.reception_date }}</span></p>{% endif %}
+<p><label>{%trans "Creation date:"%}</label> <span class='value'>{{ item.creation_date }}</span></p>
{% comment %}
{% if item.deadline_date and not item.acts %}
- <p><label>{%trans "Deadline:"%}</label><span class='value'>{% item.deadline_date %}</span></p> <!-- calculated deadline for some preventive files , see saisine_type, not displayed if an act as been send -->
+ <p><label>{%trans "Deadline:"%}</label> <span class='value'>{% item.deadline_date %}</span></p> <!-- calculated deadline for some preventive files , see saisine_type, not displayed if an act as been send -->
{% endif %}
{% endcomment %}
-<p><label>{%trans "In charge:"%}</label><span class='value'>{{ item.in_charge.full_label }}</span></p>
-<p><label>{%trans "State:"%}</label><span class='value'>{% if item.is_active %}{%trans "Active file"%}</span></p>
+<p><label>{%trans "In charge:"%}</label> <span class='value'>{{ item.in_charge.full_label }}</span></p>
+<p><label>{%trans "State:"%}</label> <span class='value'>{% if item.is_active %}{%trans "Active file"%}</span></p>
{% else %}{%trans "Closed file"%}</span></p>
-<p><label>{%trans "Closing date:"%}</label><span class='value'>{{ item.closing.date }} <strong>{%trans "by" %}</strong> {{ item.closing.user }}</span></p>
+<p><label>{%trans "Closing date:"%}</label> <span class='value'>{{ item.closing.date }} <strong>{%trans "by" %}</strong> {{ item.closing.user }}</span></p>
{% endif %}
-<p><label>{%trans "Type:"%}</label><span class='value'>{{ item.file_type }}</span></p>
+<p><label>{%trans "Type:"%}</label> <span class='value'>{{ item.file_type }}</span></p>
-{% if item.related_file %}<p><label>{%trans "Related file:"%}</label><span class='value'><a href='{% url show-file item.related_file.pk ''%}'>{{ item.related_file }}</a></span></p>{% endif %} <!-- Displayed as Year/index/Commune/Common_name This should be a link to the file sheet of the related file -->
-{% if item.comment %}<p><label>{%trans "Comment:"%}</label><span class='value'>{{ item.comment }}</span></p>{%endif%}
+{% if item.related_file %}<p><label>{%trans "Related file:"%}</label> <span class='value'><a href='{% url show-file item.related_file.pk ''%}'>{{ item.related_file }}</a></span></p>{% endif %} <!-- Displayed as Year/index/Commune/Common_name This should be a link to the file sheet of the related file -->
+{% if item.comment %}<p><label>{%trans "Comment:"%}</label> <span class='value'>{{ item.comment }}</span></p>{%endif%}
<h3>{% trans "Localisation"%}</h3>
-<p><label>{%trans "Towns:"%}</label><span class='value'>{{ item.towns.all|join:", " }}</span></p>
+<p><label>{%trans "Towns:"%}</label> <span class='value'>{{ item.towns.all|join:", " }}</span></p>
-<p><label>{%trans "Main address:"%}</label><span class='value'>{{ item.address }}</span></p>
-{% if item.address_complement %}<p><label>{%trans "Complement:"%}</label><span class='value'>{{ item.address_complement }}</span></p>{%endif%}
-{% if item.postal_code %}<p><label>{%trans "Postal code:"%}</label><span class='value'>{{ item.postal_code }}</span></p>{%endif%}
+<p><label>{%trans "Main address:"%}</label> <span class='value'>{{ item.address }}</span></p>
+{% if item.address_complement %}<p><label>{%trans "Complement:"%}</label> <span class='value'>{{ item.address_complement }}</span></p>{%endif%}
+{% if item.postal_code %}<p><label>{%trans "Postal code:"%}</label> <span class='value'>{{ item.postal_code }}</span></p>{%endif%}
-<p><label>{%trans "Surface:"%}</label><span class='value'>{{ item.total_surface }} m<sup>2</sup> ({{ item.total_surface_ha }} ha)</span></p>
+<p><label>{%trans "Surface:"%}</label> <span class='value'>{{ item.total_surface }} m<sup>2</sup> ({{ item.total_surface_ha }} ha)</span></p>
{% if item.is_preventive %}
<h3>{% trans "Preventive archaelogical file"%}</h3>
-<p><label>{%trans "Planed surface:"%}</label><span class='value'>{{ item.total_developed_surface }} m<sup>2</sup> ({{ item.total_developed_surface_ha }} ha)</span></p>
-<p><label>{%trans "Saisine type:"%}</label><span class='value'>{{ item.saisine_type }}</span></p>
-{% if item.town_planning_service %}<p><label>{%trans "Town planning service:"%}</label><span class='value'>{{ item.town_planning_service }}</span></p>{% endif %}
-{% if item.permit_type %}<p><label>{%trans "Permit type:"%}</label><span class='value'>{{ item.permit_type }}</span></p>{% endif %}
-{% if item.permit_reference %}<p><label>{%trans "Permit reference:"%}</label><span class='value'>{{ item.permit_reference }}</span></p>{% endif %}
-{% if item.general_contractor.attached_to %}<p><label>{%trans "General contractor organisation:"%}</label><span class='value'>{{ item.general_contractor.attached_to }}</span></p>{% endif %} <!-- Contractor's organisation displayed as concat of Name/Adress/postal_code/city -->
-{% if item.general_contractor %}<p><label>{%trans "General contractor:"%}</label><span class='value'>{{ item.general_contractor.full_label }}</span></p>{% endif %}
+<p><label>{%trans "Planed surface:"%}</label> <span class='value'>{{ item.total_developed_surface }} m<sup>2</sup> ({{ item.total_developed_surface_ha }} ha)</span></p>
+<p><label>{%trans "Saisine type:"%}</label> <span class='value'>{{ item.saisine_type }}</span></p>
+{% if item.town_planning_service %}<p><label>{%trans "Town planning service:"%}</label> <span class='value'>{{ item.town_planning_service }}</span></p>{% endif %}
+{% if item.permit_type %}<p><label>{%trans "Permit type:"%}</label> <span class='value'>{{ item.permit_type }}</span></p>{% endif %}
+{% if item.permit_reference %}<p><label>{%trans "Permit reference:"%}</label> <span class='value'>{{ item.permit_reference }}</span></p>{% endif %}
+{% if item.general_contractor.attached_to %}<p><label>{%trans "General contractor organisation:"%}</label> <span class='value'>{{ item.general_contractor.attached_to }}</span></p>{% endif %} <!-- Contractor's organisation displayed as concat of Name/Adress/postal_code/city -->
+{% if item.general_contractor %}<p><label>{%trans "General contractor:"%}</label> <span class='value'>{{ item.general_contractor.full_label }}</span></p>{% endif %}
{% endif %}
<table>
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;
+}
+