From af45e3f444820a00447b4c7e2e3fe158958528f3 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sun, 25 Jan 2015 18:05:09 +0100 Subject: Adapt xhtml2odt call with new tidylib --- ishtar_common/views.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'ishtar_common') diff --git a/ishtar_common/views.py b/ishtar_common/views.py index b5f56652c..6f18f8daa 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-2014 Étienne Loks +# Copyright (C) 2010-2015 Étienne Loks # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -17,10 +17,7 @@ # See the file COPYING for details. -try: - import tidy -except: - from tidylib import tidy_document as tidy +from tidylib import tidy_document as tidy import re import csv @@ -519,17 +516,15 @@ def show_item(model, name): filename = item.history_object.associated_filename else: filename = item.associated_filename - if doc_type == "odt" and settings.XHTML2ODT_PATH and \ - settings.ODT_TEMPLATE: + if doc_type == "odt" and settings.ODT_TEMPLATE: tpl = loader.get_template('ishtar/sheet_%s.html' % name) content = tpl.render(context_instance) try: - 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(" ", " ") + 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(" ", " ") html = re.sub(']*)>\n', '', html) odt = NamedTemporaryFile() -- cgit v1.2.3