[MERGE]
bzr revid: hda@hda-20090701073403-ktwglss26001w217
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -24,28 +24,26 @@ from report.render.rml2pdf import utils
|
||||
from lxml import etree
|
||||
import copy
|
||||
|
||||
|
||||
class odt2odt(object):
|
||||
def __init__(self, odt, localcontext):
|
||||
self.localcontext = localcontext
|
||||
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 +51,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,47 @@ class report_sxw(report_rml, preprocess.report):
|
||||
meta = etree.tostring(rml_dom_meta)
|
||||
|
||||
rml_dom = etree.XML(rml)
|
||||
body = rml_dom.getchildren()[-1]
|
||||
elements = []
|
||||
key1 = rml_parser.localcontext['name_space']["text"]+"p"
|
||||
key2 = rml_parser.localcontext['name_space']["text"]+"drop-down"
|
||||
for n in rml_dom.iterdescendants():
|
||||
if n.tag == key1:
|
||||
elements.append(n)
|
||||
if report_type == 'odt':
|
||||
for pe in elements:
|
||||
e = pe.findall(key2)
|
||||
for de in e:
|
||||
pp=de.getparent()
|
||||
if de.text or de.tail:
|
||||
pe.text = de.text or de.tail
|
||||
for cnd in de.getchildren():
|
||||
if cnd.text or cnd.tail:
|
||||
if pe.text:
|
||||
pe.text += cnd.text or cnd.tail
|
||||
else:
|
||||
pe.text = cnd.text or cnd.tail
|
||||
pp.remove(de)
|
||||
else:
|
||||
for pe in elements:
|
||||
e = pe.findall(key2)
|
||||
for de in e:
|
||||
pp = de.getparent()
|
||||
if de.text or de.tail:
|
||||
pe.text = de.text or de.tail
|
||||
for cnd in de:
|
||||
text = cnd.get("{http://openoffice.org/2000/text}value",False)
|
||||
if text:
|
||||
if pe.text and text.startswith('[['):
|
||||
pe.text += text
|
||||
elif text.startswith('[['):
|
||||
pe.text = text
|
||||
if de.getparent():
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user