summaryrefslogtreecommitdiff
path: root/ishtar/furnitures/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar/furnitures/views.py')
-rw-r--r--ishtar/furnitures/views.py28
1 files changed, 16 insertions, 12 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(" ", " ")
+ 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)