Commit 1c31bc9e authored by Hugo H. Maia Vieira's avatar Hugo H. Maia Vieira

Tiny refactoring


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@41633 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 12bb4c76
...@@ -31,6 +31,7 @@ from zipfile import ZipFile ...@@ -31,6 +31,7 @@ from zipfile import ZipFile
from StringIO import StringIO from StringIO import StringIO
from lxml import etree from lxml import etree
from os import path from os import path
from cloudooo.utils import logger
from cloudooo.document import OdfDocument from cloudooo.document import OdfDocument
from cloudooo.interfaces.granulate import ITableGranulator, \ from cloudooo.interfaces.granulate import ITableGranulator, \
IImageGranulator, \ IImageGranulator, \
...@@ -80,9 +81,12 @@ class OOGranulate(object): ...@@ -80,9 +81,12 @@ class OOGranulate(object):
template = ZipFile(template_path) template = ZipFile(template_path)
content_xml = etree.fromstring(template.read('content.xml')) content_xml = etree.fromstring(template.read('content.xml'))
template.close() template.close()
table = self.document.parsed_content.xpath( table_list = self.document.parsed_content.xpath(
'//table:table[@table:name="%s"]' % id, '//table:table[@table:name="%s"]' % id,
namespaces=self.document.parsed_content.nsmap)[0] namespaces=self.document.parsed_content.nsmap)
if not table_list:
return None
table = table_list[0]
# Next line do this <office:content><office:body><office:text><table:table> # Next line do this <office:content><office:body><office:text><table:table>
content_xml[-1][0].append(table) content_xml[-1][0].append(table)
# XXX: Next line replace the <office:automatic-styles> tag. This include a # XXX: Next line replace the <office:automatic-styles> tag. This include a
...@@ -97,7 +101,8 @@ class OOGranulate(object): ...@@ -97,7 +101,8 @@ class OOGranulate(object):
odf_document.close() odf_document.close()
odf_document_as_string.seek(0) odf_document_as_string.seek(0)
return odf_document_as_string.read() return odf_document_as_string.read()
except: except Exception, e:
logger.error(e)
return None return None
def getColumnItemList(self, file, table_id): def getColumnItemList(self, file, table_id):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment