[FIX]:Fixed odt2odt reports printing
bzr revid: nch@tinyerp.com-20090630133626-n4je1b30khvfwpq2
This commit is contained in:
parent
c790c9ff7d
commit
798f5d5523
|
@ -4,6 +4,7 @@ import re
|
|||
rml_parents = ['tr','story','section']
|
||||
html_parents = ['tr','body','div']
|
||||
sxw_parents = ['{http://openoffice.org/2000/table}table-row','{http://openoffice.org/2000/office}body','{http://openoffice.org/2000/text}section']
|
||||
odt_parents = ['{urn:oasis:names:tc:opendocument:xmlns:office:1.0}body','{urn:oasis:names:tc:opendocument:xmlns:table:1.0}table-row','{urn:oasis:names:tc:opendocument:xmlns:text:1.0}section']
|
||||
|
||||
class report(object):
|
||||
def preprocess_rml(self, root_node,type='pdf'):
|
||||
|
@ -37,7 +38,9 @@ class report(object):
|
|||
if len(txt.group(4)) > 1:
|
||||
return " "
|
||||
match = rml_parents
|
||||
if type in ['odt','sxw']:
|
||||
if type == 'odt':
|
||||
match = odt_parents
|
||||
if type == 'sxw':
|
||||
match = sxw_parents
|
||||
if type =='html2html':
|
||||
match = html_parents
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
from report.render.rml2pdf import utils
|
||||
from lxml import etree
|
||||
import copy
|
||||
|
||||
#sxw_parents = ['{http://openoffice.org/2000/table}table-row','{http://openoffice.org/2000/office}body','{http://openoffice.org/2000/text}section']
|
||||
#odt_parents = ['{urn:oasis:names:tc:opendocument:xmlns:office:1.0}body','{urn:oasis:names:tc:opendocument:xmlns:table:1.0}table-row','{urn:oasis:names:tc:opendocument:xmlns:text:1.0}section']
|
||||
|
||||
class odt2odt(object):
|
||||
def __init__(self, odt, localcontext):
|
||||
|
@ -31,21 +32,20 @@ class odt2odt(object):
|
|||
self.etree = odt
|
||||
self._node = None
|
||||
|
||||
|
||||
def render(self):
|
||||
def process_text(node,new_node):
|
||||
if new_node.tag in ['story','tr','section']:
|
||||
new_node.attrib.clear()
|
||||
for child in utils._child_get(node, self):
|
||||
new_child = copy.deepcopy(child)
|
||||
new_child.text = utils._process_text(self, child.text)
|
||||
new_node.append(new_child)
|
||||
if len(child):
|
||||
for n in new_child:
|
||||
new_child.text = utils._process_text(self, child.text)
|
||||
new_child.tail = utils._process_text(self, child.tail)
|
||||
new_child.remove(n)
|
||||
process_text(child, new_child)
|
||||
else:
|
||||
new_child.text = utils._process_text(self, child.text)
|
||||
new_child.tail = utils._process_text(self, child.tail)
|
||||
self._node = copy.deepcopy(self.etree)
|
||||
for n in self._node:
|
||||
self._node.remove(n)
|
||||
|
@ -53,16 +53,6 @@ class odt2odt(object):
|
|||
return self._node
|
||||
|
||||
def parseNode(node, localcontext = {}):
|
||||
body = node.getchildren()[-1]
|
||||
elements = body.findall(localcontext['name_space']["text"]+"p")
|
||||
for pe in elements:
|
||||
e = pe.findall(localcontext['name_space']["text"]+"drop-down")
|
||||
for de in e:
|
||||
pp=de.getparent()
|
||||
for cnd in de.getchildren():
|
||||
if cnd.text:
|
||||
pe.append(cnd)
|
||||
pp.remove(de)
|
||||
r = odt2odt(node, localcontext)
|
||||
return r.render()
|
||||
|
||||
|
|
|
@ -305,7 +305,7 @@ class rml_parse(object):
|
|||
head_dom = etree.XML(rml_head)
|
||||
for tag in head_dom.getchildren():
|
||||
found = rml_dom.find('.//'+tag.tag)
|
||||
if len(found):
|
||||
if found and len(found):
|
||||
if tag.get('position'):
|
||||
found.append(tag)
|
||||
else :
|
||||
|
@ -464,10 +464,29 @@ class report_sxw(report_rml, preprocess.report):
|
|||
meta = etree.tostring(rml_dom_meta)
|
||||
|
||||
rml_dom = etree.XML(rml)
|
||||
body = rml_dom.getchildren()[-1]
|
||||
elements = []
|
||||
key = rml_parser.localcontext['name_space']["text"]+'label'
|
||||
key1 = rml_parser.localcontext['name_space']["text"]+'value'
|
||||
for n in rml_dom.iterdescendants():
|
||||
if n.tag == rml_parser.localcontext['name_space']["text"]+"p":
|
||||
elements.append(n)
|
||||
for pe in elements:
|
||||
e = pe.findall(rml_parser.localcontext['name_space']["text"]+"drop-down")
|
||||
for de in e:
|
||||
pp=de.getparent()
|
||||
for cnd in de.getchildren():
|
||||
if cnd.text or cnd.tail:
|
||||
if de.text or de.tail:
|
||||
pe.text = de.text or de.tail
|
||||
if pe.text:
|
||||
pe.text += cnd.text or cnd.tail
|
||||
else:
|
||||
pe.text = cnd.text or cnd.tail
|
||||
pp.remove(de)
|
||||
rml_dom = self.preprocess_rml(rml_dom,report_type)
|
||||
create_doc = self.generators[report_type]
|
||||
odt = etree.tostring(create_doc(rml_dom, rml_parser.localcontext))
|
||||
|
||||
sxw_z = zipfile.ZipFile(sxw_io, mode='a')
|
||||
sxw_z.writestr('content.xml', "<?xml version='1.0' encoding='UTF-8'?>" + \
|
||||
odt)
|
||||
|
|
Loading…
Reference in New Issue