diff options
| author | hda (Tiny) <hda@tinyerp.com> | 2009-12-08 15:42:46 +0530 |
|---|---|---|
| committer | hda (Tiny) <hda@tinyerp.com> | 2009-12-08 15:42:46 +0530 |
| commit | 24cd74becf6df66c71cdafc9f8a41ffdde903aec (patch) | |
| tree | cf195d12fdbdbeadd6de930c93e54b01fa959a23 /bin/report | |
| parent | a481bfb190667cd2fcb6335adf533afe6e1c8e2d (diff) | |
| parent | 474af4cd6e6f00759589c4bee9cebf9d7d26b0d8 (diff) | |
Merge
bzr revid: hda@tinyerp.com-20091208101246-5ave2zzgzsjqf0m8
Diffstat (limited to 'bin/report')
| -rw-r--r-- | bin/report/custom.py | 112 | ||||
| -rw-r--r-- | bin/report/interface.py | 56 | ||||
| -rw-r--r-- | bin/report/print_xml.py | 27 | ||||
| -rw-r--r-- | bin/report/printscreen/ps_form.py | 39 | ||||
| -rw-r--r-- | bin/report/printscreen/ps_list.py | 62 | ||||
| -rw-r--r-- | bin/report/render/html2html/html2html.py | 2 | ||||
| -rw-r--r-- | bin/report/render/rml2html/rml2html.py | 10 | ||||
| -rw-r--r-- | bin/report/render/rml2pdf/trml2pdf.py | 7 | ||||
| -rw-r--r-- | bin/report/render/rml2pdf/utils.py | 14 | ||||
| -rw-r--r-- | bin/report/report_sxw.py | 28 |
10 files changed, 126 insertions, 231 deletions
diff --git a/bin/report/custom.py b/bin/report/custom.py index 4c0c9b1ece0..bb1b32c0e43 100644 --- a/bin/report/custom.py +++ b/bin/report/custom.py @@ -33,12 +33,10 @@ from osv.osv import except_osv from osv.orm import browse_null from osv.orm import browse_record_list import pooler -from xml.dom import minidom -import libxml2 -import libxslt from pychart import * import misc import cStringIO +from lxml import etree class external_pdf(render.render): def __init__(self, pdf): @@ -287,17 +285,13 @@ class report_custom(report_int): if report['print_orientation']=='landscape': pageSize=[pageSize[1],pageSize[0]] - impl = minidom.getDOMImplementation() - new_doc = impl.createDocument(None, "report", None) + new_doc = etree.Element('report') - # build header - config = new_doc.createElement("config") + config = etree.SubElement(new_doc, 'config') def _append_node(name, text): - n = new_doc.createElement(name) - t = new_doc.createTextNode(text) - n.appendChild(t) - config.appendChild(n) + n = etree.SubElement(config, name) + t.text = text _append_node('date', time.strftime('%d/%m/%Y')) _append_node('PageFormat', '%s' % report['print_format']) @@ -317,45 +311,33 @@ class report_custom(report_int): _append_node('report-header', '%s' % (report['title'],)) _append_node('report-footer', '%s' % (report['footer'],)) - new_doc.childNodes[0].appendChild(config) - header = new_doc.createElement("header") - + header = etree.SubElement(new_doc, 'header') for f in fields: - field = new_doc.createElement("field") - field_txt = new_doc.createTextNode('%s' % (f['name'],)) - field.appendChild(field_txt) - header.appendChild(field) - - new_doc.childNodes[0].appendChild(header) + field = etree.SubElement(header, 'field') + field.text = f['name'] - lines = new_doc.createElement("lines") + lines = etree.SubElement(new_doc, 'lines') level.reverse() for line in results: shift = level.pop() - node_line = new_doc.createElement("row") + node_line = etree.SubElement(lines, 'row') prefix = '+' for f in range(len(fields)): - col = new_doc.createElement("col") + col = etree.SubElement(node_line, 'col') if f == 0: - col.setAttribute('para','yes') - col.setAttribute('tree','yes') - col.setAttribute('space',str(3*shift)+'mm') + col.attrib.update(para='yes', + tree='yes', + space=str(3*shift)+'mm') if line[f] != None: - txt = new_doc.createTextNode(prefix+str(line[f]) or '') + col.text = prefix+str(line[f]) or '' else: - txt = new_doc.createTextNode('/') - col.appendChild(txt) - node_line.appendChild(col) + col.text = '/' prefix = '' - lines.appendChild(node_line) - - new_doc.childNodes[0].appendChild(lines) - styledoc = libxml2.parseFile(os.path.join(tools.config['root_path'],'addons/base/report/custom_new.xsl')) - style = libxslt.parseStylesheetDoc(styledoc) - doc = libxml2.parseDoc(new_doc.toxml()) - rml_obj = style.applyStylesheet(doc, None) - rml = style.saveResultToString(rml_obj) + transform = etree.XSLT( + etree.parse(os.path.join(tools.config['root_path'], + 'addons/base/report/custom_new.xsl'))) + rml = etree.tostring(transform(new_doc)) self.obj = render.rml(rml) self.obj.render() @@ -592,17 +574,12 @@ class report_custom(report_int): if report['print_orientation']=='landscape': pageSize=[pageSize[1],pageSize[0]] - impl = minidom.getDOMImplementation() - new_doc = impl.createDocument(None, "report", None) - - # build header - config = new_doc.createElement("config") + new_doc = etree.Element('report') + config = etree.SubElement(new_doc, 'config') def _append_node(name, text): - n = new_doc.createElement(name) - t = new_doc.createTextNode(text) - n.appendChild(t) - config.appendChild(n) + n = etree.SubElement(config, name) + n.text = text _append_node('date', time.strftime('%d/%m/%Y')) _append_node('PageSize', '%.2fmm,%.2fmm' % tuple(pageSize)) @@ -622,40 +599,25 @@ class report_custom(report_int): _append_node('report-header', '%s' % (report['title'],)) _append_node('report-footer', '%s' % (report['footer'],)) - new_doc.childNodes[0].appendChild(config) - header = new_doc.createElement("header") - + header = etree.SubElement(new_doc, 'header') for f in fields: - field = new_doc.createElement("field") - field_txt = new_doc.createTextNode('%s' % (f['name'],)) - field.appendChild(field_txt) - header.appendChild(field) - - new_doc.childNodes[0].appendChild(header) + field = etree.SubElement(header, 'field') + field.text = f['name'] - lines = new_doc.createElement("lines") + lines = etree.SubElement(new_doc, 'lines') for line in results: - node_line = new_doc.createElement("row") + node_line = etree.SubElement(lines, 'row') for f in range(len(fields)): - col = new_doc.createElement("col") - col.setAttribute('tree','no') + col = etree.SubElement(node_line, 'col', tree='no') if line[f] != None: - txt = new_doc.createTextNode(str(line[f] or '')) + col.text = line[f] or '' else: - txt = new_doc.createTextNode('/') - col.appendChild(txt) - node_line.appendChild(col) - lines.appendChild(node_line) - - new_doc.childNodes[0].appendChild(lines) - -# file('/tmp/terp.xml','w+').write(new_doc.toxml()) - - styledoc = libxml2.parseFile(os.path.join(tools.config['root_path'],'addons/base/report/custom_new.xsl')) - style = libxslt.parseStylesheetDoc(styledoc) - doc = libxml2.parseDoc(new_doc.toxml()) - rml_obj = style.applyStylesheet(doc, None) - rml = style.saveResultToString(rml_obj) + col.text = '/' + + transform = etree.XSLT( + etree.parse(os.path.join(tools.config['root_path'], + 'addons/base/report/custom_new.xsl'))) + rml = etree.tostring(transform(new_doc)) self.obj = render.rml(rml) self.obj.render() diff --git a/bin/report/interface.py b/bin/report/interface.py index cd548301c26..2bafcf3bb1a 100644 --- a/bin/report/interface.py +++ b/bin/report/interface.py @@ -23,8 +23,6 @@ import os import re -import libxml2 -import libxslt from lxml import etree import netsvc import pooler @@ -145,48 +143,34 @@ class report_rml(report_int): if not self.xsl: return xml - # load XSL (parse it to the XML level) - styledoc = libxml2.parseDoc(tools.file_open(self.xsl).read()) - xsl_path, tail = os.path.split(self.xsl) - for child in styledoc.children: - if child.name == 'import': - if child.hasProp('href'): - imp_file = child.prop('href') - _x, imp_file = tools.file_open(imp_file, subdir=xsl_path, pathinfo=True) - child.setProp('href', urllib.quote(str(imp_file))) + stylesheet = etree.parse(tools.file_open(self.xsl)) + xsl_path, _ = os.path.split(self.xsl) + for import_child in stylesheet.findall('./import'): + if 'href' in import_child.attrib: + imp_file = import_child.get('href') + _, imp_file = tools.file_open(imp_file, subdir=xsl_path, pathinfo=True) + import_child.set('href', urllib.quote(str(imp_file))) #TODO: get all the translation in one query. That means we have to: # * build a list of items to translate, # * issue the query to translate them, # * (re)build/update the stylesheet with the translated items - # translate the XSL stylesheet - def look_down(child, lang): - while child is not None: - if (child.type == "element") and child.hasProp('t'): - #FIXME: use cursor - res = service.execute(cr.dbname, uid, 'ir.translation', - '_get_source', self.name2, 'xsl', lang, child.content) - if res: - child.setContent(res.encode('utf-8')) - look_down(child.children, lang) - child = child.next + def translate(doc, lang): + for node in doc.xpath('//*[@t]'): + translation = service.execute( + cr.dbname, uid, 'ir.translation', '_get_source', + self.name2, 'xsl', lang, node.text) + if translation: + node.text = translation if context.get('lang', False): - look_down(styledoc.children, context['lang']) - - # parse XSL - style = libxslt.parseStylesheetDoc(styledoc) - # load XML (data) - doc = libxml2.parseMemory(xml,len(xml)) - # create RML (apply XSL to XML data) - result = style.applyStylesheet(doc, None) - # save result to string - xml = style.saveResultToString(result) - - style.freeStylesheet() - doc.freeDoc() - result.freeDoc() + translate(stylesheet, context['lang']) + + transform = etree.XSLT(stylesheet) + xml = etree.tostring( + transform(etree.fromstring(xml))) + return xml def create_pdf(self, rml, localcontext = None, logo=None, title=None): diff --git a/bin/report/print_xml.py b/bin/report/print_xml.py index 912fdad00a3..9eb038e7463 100644 --- a/bin/report/print_xml.py +++ b/bin/report/print_xml.py @@ -122,8 +122,7 @@ class document(object): #TODO: test this if value == '' and 'default' in attrs: value = attrs['default'] - el = etree.Element(node.tag) - parent.append(el) + el = etree.SubElement(parent, node.tag) el.text = tounicode(value) #TODO: test this for key, value in attrs.iteritems(): @@ -155,31 +154,27 @@ class document(object): fp.write(dt) i = str(len(self.bin_datas)) self.bin_datas[i] = fp - el = etree.Element(node.tag) + el = etree.SubElement(parent, node.tag) el.text = i - parent.append(el) elif attrs['type']=='data': #TODO: test this txt = self.datas.get('form', {}).get(attrs['name'], '') - el = etree.Element(node.tag) + el = etree.SubElement(parent, node.tag) el.text = txt - parent.append(el) elif attrs['type']=='function': if attrs['name'] in self.func: txt = self.func[attrs['name']](node) else: txt = print_fnc.print_fnc(attrs['name'], node) - el = etree.Element(node.tag) + el = etree.SubElement(parent, node.tag) el.text = txt - parent.append(el) elif attrs['type']=='eval': value = self.eval(browser, attrs['expr']) - el = etree.Element(node.tag) + el = etree.SubElement(parent, node.tag) el.text = str(value) - parent.append(el) elif attrs['type']=='fields': fields = attrs['name'].split(',') @@ -197,8 +192,7 @@ class document(object): v_list = [vals[k] for k in keys] for v in v_list: - el = etree.Element(node.tag) - parent.append(el) + el = etree.SubElement(parent, node.tag) for el_cld in node: self.parse_node(el_cld, el, v) @@ -232,8 +226,7 @@ class document(object): def parse_result_tree(node, parent, datas): if not node.tag == etree.Comment: - el = etree.Element(node.tag) - parent.append(el) + el = etree.SubElement(parent, node.tag) atr = self.node_attrs_get(node) if 'value' in atr: if not isinstance(datas[atr['value']], (str, unicode)): @@ -257,8 +250,7 @@ class document(object): else: v_list = value for v in v_list: - el = etree.Element(node.tag) - parent.append(el) + el = etree.SubElement(parent, node.tag) for el_cld in node: self.parse_node(el_cld, el, v) else: @@ -267,8 +259,7 @@ class document(object): if node.tag == parent.tag: el = parent else: - el = etree.Element(node.tag) - parent.append(el) + el = etree.SubElement(parent, node.tag) for el_cld in node: self.parse_node(el_cld,el, browser) def xml_get(self): diff --git a/bin/report/printscreen/ps_form.py b/bin/report/printscreen/ps_form.py index ac9c499dda3..5e2c7285206 100644 --- a/bin/report/printscreen/ps_form.py +++ b/bin/report/printscreen/ps_form.py @@ -26,8 +26,6 @@ import tools from report import render from lxml import etree -import libxml2 -import libxslt import time, os @@ -78,21 +76,18 @@ class report_printscreen_list(report_int): def _create_table(self, uid, ids, fields, fields_order, results, context, title=''): pageSize=[297.0,210.0] - impl = minidom.getDOMImplementation() new_doc = etree.Element("report") - config = etree.Element("config") + config = etree.SubElement(new_doc, 'config') # build header def _append_node(name, text): - n = etree.Element(name) + n = etree.SubElement(config, name) n.text = text - config.append(n) _append_node('date', time.strftime('%d/%m/%Y')) _append_node('PageSize', '%.2fmm,%.2fmm' % tuple(pageSize)) _append_node('PageWidth', '%.2f' % (pageSize[0] * 2.8346,)) _append_node('PageHeight', '%.2f' %(pageSize[1] * 2.8346,)) - _append_node('report-header', title) l = [] @@ -111,17 +106,15 @@ class report_printscreen_list(report_int): s = fields[fields_order[pos]].get('size', 56) / 28 + 1 l[pos] = strmax * s / t _append_node('tableSize', ','.join(map(str,l)) ) - new_doc.append(config) - header=etree.Element("header") + header = etree.SubElement(new_doc, 'header') for f in fields_order: - field = etree.Element("field") + field = etree.SubElement(header, 'field') field.text = fields[f]['string'] or '' - header.append(field) - new_doc.append(header) - lines = etree.Element("lines") + + lines = etree.SubElement(new_doc, 'lines') for line in results: - node_line = etree.Element("row") + node_line = etree.SubElement(lines, 'row') for f in fields_order: if fields[f]['type']=='many2one' and line[f]: line[f] = line[f][1] @@ -130,21 +123,17 @@ class report_printscreen_list(report_int): if fields[f]['type'] == 'float': precision=(('digits' in fields[f]) and fields[f]['digits'][1]) or 2 line[f]=round(line[f],precision) - col = etree.Element("col") - col.set('tree','no') + col = etree.SubElement(node_line, 'col', tree='no') if line[f] != None: col.text = tools.ustr(line[f] or '') else: col.text = '/' - node_line.append(col) - lines.append(node_line) - new_doc.append(node_line) - - styledoc = libxml2.parseFile(os.path.join(tools.config['root_path'],'addons/base/report/custom_new.xsl')) - style = libxslt.parseStylesheetDoc(styledoc) - doc = libxml2.parseDoc(new_doc.toxml()) - rml_obj = style.applyStylesheet(doc, None) - rml = style.saveResultToString(rml_obj) + + transform = etree.XSLT( + etree.parse(os.path.join(tools.config['root_path'], + 'addons/base/report/custom_new.xsl'))) + rml = etree.tostring(transform(new_doc)) + self.obj = render.rml(rml, self.title) self.obj.render() return True diff --git a/bin/report/printscreen/ps_list.py b/bin/report/printscreen/ps_list.py index d2f946e6715..37a9adda880 100644 --- a/bin/report/printscreen/ps_list.py +++ b/bin/report/printscreen/ps_list.py @@ -25,8 +25,6 @@ import pooler import tools from lxml import etree from report import render -import libxml2 -import libxslt import locale import time, os @@ -38,14 +36,9 @@ class report_printscreen_list(report_int): def _parse_node(self, root_node): result = [] - for node in root_node.getchildren(): + for node in root_node: if node.tag == 'field': - attrsa = node.attrib - attrs = {} - if not attrsa is None: - for key,val in attrsa.items(): - attrs[key] = val - result.append(attrs['name']) + result.append(node.get('name')) else: result.extend(self._parse_node(node)) return result @@ -91,30 +84,28 @@ class report_printscreen_list(report_int): def _create_table(self, uid, ids, fields, fields_order, results, context, title=''): pageSize=[297.0, 210.0] - new_doc = etree.Element("report") - config = etree.Element("config") - # build header + new_doc = etree.Element("report") + config = etree.SubElement(new_doc, 'config') def _append_node(name, text): - n = etree.Element(name) + n = etree.SubElement(config, name) n.text = text - config.append(n) #_append_node('date', time.strftime('%d/%m/%Y')) _append_node('date', time.strftime(str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y')))) _append_node('PageSize', '%.2fmm,%.2fmm' % tuple(pageSize)) _append_node('PageWidth', '%.2f' % (pageSize[0] * 2.8346,)) _append_node('PageHeight', '%.2f' %(pageSize[1] * 2.8346,)) - _append_node('report-header', title) + l = [] t = 0 rowcount=0; strmax = (pageSize[0]-40) * 2.8346 temp = [] count = len(fields_order) - for i in range(0,count): + for i in range(0, count): temp.append(0) ince = -1; @@ -136,24 +127,20 @@ class report_printscreen_list(report_int): l[pos] = strmax * s / t _append_node('tableSize', ','.join(map(str,l)) ) - new_doc.append(config) - header=etree.Element("header") - + header = etree.SubElement(new_doc, 'header') for f in fields_order: - field = etree.Element("field") + field = etree.SubElement(header, 'field') field.text = tools.ustr(fields[f]['string'] or '') - header.append(field) - new_doc.append(header) - lines = etree.Element("lines") + lines = etree.SubElement(new_doc, 'lines') tsum = [] count = len(fields_order) for i in range(0,count): tsum.append(0) for line in results: - node_line = etree.Element("row") + node_line = etree.SubElement(lines, 'row') count = -1 for f in fields_order: float_flag = 0 @@ -195,28 +182,19 @@ class report_printscreen_list(report_int): new_d1 = d1.strftime(format) line[f] = new_d1 - col = etree.Element("col") - col.set('para','yes') - col.set('tree','no') + col = etree.SubElement(node_line, 'col', para='yes', tree='no') if line[f] != None: col.text = tools.ustr(line[f] or '') if float_flag: col.set('tree','float') if temp[count] == 1: tsum[count] = float(tsum[count]) + float(line[f]); - - else: col.text = '/' - node_line.append(col) - lines.append(node_line) - node_line = etree.Element("row") - lines.append(node_line) + node_line = etree.SubElement(lines, 'row') for f in range(0,count+1): - col = etree.Element("col") - col.set('para','yes') - col.set('tree','no') + col = etree.SubElement(node_line, 'col', para='yes', tree='no') if tsum[f] != None: if tsum[f] >= 0.01 : prec = '%.' + str(tools.config['price_accuracy']) + 'f' @@ -231,16 +209,12 @@ class report_printscreen_list(report_int): txt ='Total' col.text = tools.ustr(txt or '') - node_line.append(col) - lines.append(node_line) + transform = etree.XSLT( + etree.parse(os.path.join(tools.config['root_path'], + 'addons/base/report/custom_new.xsl'))) + rml = etree.tostring(transform(new_doc)) - new_doc.append(lines) - styledoc = libxml2.parseFile(os.path.join(tools.config['root_path'],'addons/base/report/custom_new.xsl')) - style = libxslt.parseStylesheetDoc(styledoc) - doc = libxml2.parseDoc(etree.tostring(new_doc)) - rml_obj = style.applyStylesheet(doc, None) - rml = style.saveResultToString(rml_obj) self.obj = render.rml(rml, title=self.title) self.obj.render() return True diff --git a/bin/report/render/html2html/html2html.py b/bin/report/render/html2html/html2html.py index fa07e9b4726..9f81e26d4f2 100644 --- a/bin/report/render/html2html/html2html.py +++ b/bin/report/render/html2html/html2html.py @@ -75,7 +75,7 @@ class html2html(object): return self._node def url_modify(self,root): - for n in root.getchildren(): + for n in root: if (n.text.find('<a ')>=0 or n.text.find('<a')>=0) and n.text.find('href')>=0 and n.text.find('style')<=0 : node = (n.tag=='span' and n.getparent().tag=='u') and n.getparent().getparent() or ((n.tag=='span') and n.getparent()) or n style = node.get('color') and "style='color:%s; text-decoration: none;'"%node.get('color') or '' diff --git a/bin/report/render/rml2html/rml2html.py b/bin/report/render/rml2html/rml2html.py index 8f0197b32df..a3a14fc8aee 100644 --- a/bin/report/render/rml2html/rml2html.py +++ b/bin/report/render/rml2html/rml2html.py @@ -104,12 +104,10 @@ class _flowable(object): process(node,new_node) if new_node.get('colWidths',False): sizes = map(lambda x: utils.unit_get(x), new_node.get('colWidths').split(',')) - tr = etree.Element('tr') + tr = etree.SubElement(new_node, 'tr') for s in sizes: - td = etree.Element('td') - td.set("width", str(s)) - tr.append(td) - new_node.append(tr) + etree.SubElement(tr, 'td', width=str(s)) + return etree.tostring(new_node) def _tag_para(self, node): @@ -298,7 +296,7 @@ class _rml_template(object): posx = int(utils.unit_get(tmpl.get('x1'))) frames[(posy,posx,tmpl.get('id'))] = _rml_tmpl_frame(posx, utils.unit_get(tmpl.get('width'))) for tmpl in pt.findall('pageGraphics'): - for n in tmpl.getchildren(): + for n in tmpl: if n.tag == 'image': self.data = rc + utils._process_text(self, n.text) if n.tag in self._tags: diff --git a/bin/report/render/rml2pdf/trml2pdf.py b/bin/report/render/rml2pdf/trml2pdf.py index b3585254eb3..b7db9724781 100644 --- a/bin/report/render/rml2pdf/trml2pdf.py +++ b/bin/report/render/rml2pdf/trml2pdf.py @@ -88,7 +88,7 @@ class _rml_styles(object,): def _table_style_get(self, style_node): styles = [] - for node in style_node.getchildren(): + for node in style_node: start = utils.tuple_int_get(node, 'start', (0,0) ) stop = utils.tuple_int_get(node, 'stop', (-1,-1) ) if node.tag=='blockValign': @@ -166,7 +166,7 @@ class _rml_doc(object): def _textual_image(self, node): rc = '' - for n in node.getchildren(): + for n in node: rc +=( etree.tostring(n) or '') + n.tail return base64.decodestring(node.tostring()) @@ -749,7 +749,8 @@ class _rml_template(object): frame.lastFrame = True frames.append( frame ) try : - gr = pt.findall('pageGraphics') or pt.getchildren()[1].findall('pageGraphics') + gr = pt.findall('pageGraphics')\ + or pt[1].findall('pageGraphics') except : gr='' if len(gr): diff --git a/bin/report/render/rml2pdf/utils.py b/bin/report/render/rml2pdf/utils.py index abc421a0f2f..bbccd23bb28 100644 --- a/bin/report/render/rml2pdf/utils.py +++ b/bin/report/render/rml2pdf/utils.py @@ -56,7 +56,7 @@ def xml2str(s): def _child_get(node, self=None, tagname=None): for n in node: - if self and self.localcontext and n.get('rml_loop', False): + if self and self.localcontext and n.get('rml_loop'): oldctx = self.localcontext for ctx in eval(n.get('rml_loop'),{}, self.localcontext): @@ -80,12 +80,12 @@ def _child_get(node, self=None, tagname=None): yield n self.localcontext = oldctx continue - if self and self.localcontext and n.get('rml_except', False): + if self and self.localcontext and n.get('rml_except'): try: eval(n.get('rml_except'), {}, self.localcontext) except: continue - if self and self.localcontext and n.get('rml_tag', False): + if self and self.localcontext and n.get('rml_tag'): try: (tag,attr) = eval(n.get('rml_tag'),{}, self.localcontext) n2 = copy.deepcopy(n) @@ -125,10 +125,7 @@ def _process_text(self, txt): return result def text_get(node): - rc = '' - for node in node.getchildren(): - rc = rc + tools.ustr(node.text) - return rc + return ''.join([tools.ustr(n.text) for n in node]) units = [ (re.compile('^(-?[0-9\.]+)\s*in$'), reportlab.lib.units.inch), @@ -158,8 +155,7 @@ def unit_get(size): def tuple_int_get(node, attr_name, default=None): if not node.get(attr_name): return default - res = [int(x) for x in node.get(attr_name).split(',')] - return res + return map(int, node.get(attr_name).split(',')) def bool_get(value): return (str(value)=="1") or (value.lower()=='yes') diff --git a/bin/report/report_sxw.py b/bin/report/report_sxw.py index 1adca0b8176..0364511da13 100644 --- a/bin/report/report_sxw.py +++ b/bin/report/report_sxw.py @@ -303,7 +303,7 @@ class rml_parse(object): rml_head = rml_head.replace('<image','<!--image') rml_head = rml_head.replace('</image>','</image-->') head_dom = etree.XML(rml_head) - for tag in head_dom.getchildren(): + for tag in head_dom: found = rml_dom.find('.//'+tag.tag) if found is not None and len(found): if tag.get('position'): @@ -462,13 +462,14 @@ class report_sxw(report_rml, preprocess.report): for pe in elements: if pe.get(rml_parser.localcontext['name_space']["meta"]+"name"): if pe.get(rml_parser.localcontext['name_space']["meta"]+"name") == "Info 3": - pe.getchildren()[0].text=data['id'] + pe[0].text=data['id'] if pe.get(rml_parser.localcontext['name_space']["meta"]+"name") == "Info 4": - pe.getchildren()[0].text=data['model'] - meta = etree.tostring(rml_dom_meta) + pe[0].text=data['model'] + meta = etree.tostring(rml_dom_meta, encoding='utf-8', + xml_declaration=True) rml_dom = etree.XML(rml) - body = rml_dom.getchildren()[-1] + body = rml_dom[-1] elements = [] key1 = rml_parser.localcontext['name_space']["text"]+"p" key2 = rml_parser.localcontext['name_space']["text"]+"drop-down" @@ -482,7 +483,7 @@ class report_sxw(report_rml, preprocess.report): pp=de.getparent() if de.text or de.tail: pe.text = de.text or de.tail - for cnd in de.getchildren(): + for cnd in de: if cnd.text or cnd.tail: if pe.text: pe.text += cnd.text or cnd.tail @@ -508,12 +509,11 @@ class report_sxw(report_rml, preprocess.report): 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)) + odt = etree.tostring(create_doc(rml_dom, rml_parser.localcontext), + encoding='utf-8', xml_declaration=True) sxw_z = zipfile.ZipFile(sxw_io, mode='a') - sxw_z.writestr('content.xml', "<?xml version='1.0' encoding='UTF-8'?>" + \ - odt) - sxw_z.writestr('meta.xml', "<?xml version='1.0' encoding='UTF-8'?>" + \ - meta) + sxw_z.writestr('content.xml', odt) + sxw_z.writestr('meta.xml', meta) if report_xml.header: #Add corporate header/footer @@ -528,9 +528,9 @@ class report_sxw(report_rml, preprocess.report): odt = create_doc(rml_dom,rml_parser.localcontext) if report_xml.header: rml_parser._add_header(odt) - odt = etree.tostring(odt) - sxw_z.writestr('styles.xml',"<?xml version='1.0' encoding='UTF-8'?>" + \ - odt) + odt = etree.tostring(odt, encoding='utf-8', + xml_declaration=True) + sxw_z.writestr('styles.xml', odt) sxw_z.close() final_op = sxw_io.getvalue() sxw_io.close() |
