summaryrefslogtreecommitdiff
path: root/bin/report/render
diff options
context:
space:
mode:
authorP. Christeas <p_christ@hol.gr>2009-07-09 21:12:53 +0300
committerP. Christeas <p_christ@hol.gr>2009-07-09 21:12:53 +0300
commit2d64ce69d07a55f827548e43cfcc73cd459dc39a (patch)
treeb217b2afe155395280d27a4c6cc0c43c89396c3b /bin/report/render
parentcb5e80507f5a8330ed4e0f2526343b97f8d506e6 (diff)
parenta2db1c09ba3a279a8d791c8914a19d2f0dbb2c18 (diff)
Merge origin/master into mdv-gpl3-py26
Conflicts: bin/addons/base_setup/i18n/base_setup.pot bin/openerp-server.py bin/report/preprocess.py bin/report/report_sxw.py bin/tools/translate.py bzr revid: p_christ@hol.gr-20090709181253-fu8nxy9b3ykrrd1c
Diffstat (limited to 'bin/report/render')
-rw-r--r--bin/report/render/html2html/html2html.py23
-rw-r--r--bin/report/render/odt2odt/odt2odt.py17
-rw-r--r--bin/report/render/rml2pdf/trml2pdf.py14
-rw-r--r--bin/report/render/rml2pdf/utils.py19
4 files changed, 49 insertions, 24 deletions
diff --git a/bin/report/render/html2html/html2html.py b/bin/report/render/html2html/html2html.py
index d4fa8559720..fa07e9b4726 100644
--- a/bin/report/render/html2html/html2html.py
+++ b/bin/report/render/html2html/html2html.py
@@ -30,7 +30,7 @@ import re
from reportlab.lib.utils import ImageReader
_regex = re.compile('\[\[(.+?)\]\]')
-
+utils._regex = re.compile('\[\[\s*(.+?)\s*\]\]',re.DOTALL)
class html2html(object):
def __init__(self, html, localcontext):
self.localcontext = localcontext
@@ -47,6 +47,8 @@ class html2html(object):
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:
@@ -65,13 +67,30 @@ class html2html(object):
else :
new_child.getparent().remove(new_child)
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)
process_text(self.etree, self._node)
return self._node
+
+ def url_modify(self,root):
+ for n in root.getchildren():
+ if (n.text.find('<a ')>=0 or n.text.find('&lt;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 ''
+ if n.text.find('&lt;a')>=0:
+ t = '&lt;a '
+ else :
+ t = '<a '
+ href = n.text.split(t)[-1]
+ n.text = ' '.join([t,style,href])
+ self.url_modify(n)
+ return root
def parseString(node, localcontext = {}):
r = html2html(node, localcontext)
- return r.render()
+ root = r.render()
+ root = r.url_modify(root)
+ return root
diff --git a/bin/report/render/odt2odt/odt2odt.py b/bin/report/render/odt2odt/odt2odt.py
index 4f4b7172ee1..65b6249c83e 100644
--- a/bin/report/render/odt2odt/odt2odt.py
+++ b/bin/report/render/odt2odt/odt2odt.py
@@ -24,27 +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_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)
@@ -52,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()
diff --git a/bin/report/render/rml2pdf/trml2pdf.py b/bin/report/render/rml2pdf/trml2pdf.py
index 8feac0260d4..7b48031d390 100644
--- a/bin/report/render/rml2pdf/trml2pdf.py
+++ b/bin/report/render/rml2pdf/trml2pdf.py
@@ -256,16 +256,19 @@ class _rml_canvas(object):
def _drawString(self, node):
v = utils.attr_get(node, ['x','y'])
text=self._textual(node, **v)
+ text = utils.xml2str(text)
self.canvas.drawString(text=text, **v)
def _drawCenteredString(self, node):
v = utils.attr_get(node, ['x','y'])
text=self._textual(node, **v)
+ text = utils.xml2str(text)
self.canvas.drawCentredString(text=text, **v)
def _drawRightString(self, node):
v = utils.attr_get(node, ['x','y'])
text=self._textual(node, **v)
+ text = utils.xml2str(text)
self.canvas.drawRightString(text=text, **v)
def _rect(self, node):
@@ -470,11 +473,11 @@ class _rml_flowable(object):
for key in txt_n.attrib.keys():
if key in ('rml_except', 'rml_loop', 'rml_tag'):
del txt_n.attrib[key]
- if not self._textual(n).isspace():
+ if True or not self._textual(n).isspace():
txt_n.text = self._textual(n)
txt_n.tail = ''
rc1 += etree.tostring(txt_n)
- rc1 += utils._process_text(self, node.tail or '')
+ #rc1 += utils._process_text(self, node.tail or '')
return rc1
def _table(self, node):
@@ -590,7 +593,7 @@ class _rml_flowable(object):
from reportlab.graphics.barcode import usps
except Exception, e:
return None
- args = utils.attr_get(node, [], {'ratio':'float','xdim':'unit','height':'unit','checksum':'bool','quiet':'bool'})
+ args = utils.attr_get(node, [], {'ratio':'float','xdim':'unit','height':'unit','checksum':'int','quiet':'int','width':'unit','stop':'bool','bearers':'int','barWidth':'float','barHeight':'float'})
codes = {
'codabar': lambda x: common.Codabar(x, **args),
'code11': lambda x: common.Code11(x, **args),
@@ -779,8 +782,13 @@ class _rml_template(object):
def render(self, node_stories):
fis = []
r = _rml_flowable(self.doc,self.localcontext, images=self.images, path=self.path, title=self.title)
+ story_cnt = 0
for node_story in node_stories:
fis += r.render(node_story)
+ if self.localcontext:
+ story_cnt += 1
+ if story_cnt == len(self.localcontext['objects']):
+ fis.append(PageCount())
fis.append(platypus.PageBreak())
self.doc_tmpl.build(fis)
diff --git a/bin/report/render/rml2pdf/utils.py b/bin/report/render/rml2pdf/utils.py
index 8d10629a6f6..5fe96631fac 100644
--- a/bin/report/render/rml2pdf/utils.py
+++ b/bin/report/render/rml2pdf/utils.py
@@ -44,6 +44,12 @@ import copy
_regex = re.compile('\[\[(.+?)\]\]')
+def str2xml(s):
+ return s.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
+
+def xml2str(s):
+ return s.replace('&amp;','&').replace('&lt;','<').replace('&gt;','>')
+
def _child_get(node, self=None, tagname=None):
for n in node:
if self and self.localcontext and n.get('rml_loop', False):
@@ -100,13 +106,14 @@ def _process_text(self, txt):
result += self.localcontext.get('translate', lambda x:x)(sps.pop(0))
if sps:
try:
- txt2 = eval(sps.pop(0),self.localcontext)
+ txt = eval(sps.pop(0),self.localcontext)
except:
- txt2 = ''
- if type(txt2) == type(0) or type(txt2) == type(0.0):
- txt2 = str(txt2)
- if type(txt2)==type('') or type(txt2)==type(u''):
+ pass
+ if type(txt)==type('') or type(txt)==type(u''):
+ txt2 = str2xml(txt)
result += txt2
+ elif (txt is not None) and (txt is not False):
+ result += str(txt)
return result
def text_get(node):
@@ -155,6 +162,8 @@ def attr_get(node, attrs, dict={}):
res[key] = int(node.get(key))
elif dict[key]=='unit':
res[key] = unit_get(node.get(key))
+ elif dict[key] == 'float' :
+ res[key] = float(node.get(key))
return res
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: