changes in report engine for html2html
bzr revid: dsh@tinyerp.com-20090505114227-mp9ndr3rkbkycfl7
This commit is contained in:
parent
3d818a0f1a
commit
5c828843a9
|
@ -82,6 +82,7 @@ class report_rml(report_int):
|
|||
'raw': self.create_raw,
|
||||
'sxw': self.create_sxw,
|
||||
'odt': self.create_odt,
|
||||
'html2html' : self.create_html2html,
|
||||
}
|
||||
|
||||
def create(self, cr, uid, ids, datas, context):
|
||||
|
@ -203,6 +204,11 @@ class report_rml(report_int):
|
|||
obj.render()
|
||||
return obj.get()
|
||||
|
||||
def create_html2html(self, rml, localcontext = None, logo=None, title=None):
|
||||
obj = render.html2html(rml, localcontext, self.bin_datas)
|
||||
obj.render()
|
||||
return obj.get()
|
||||
|
||||
def create_raw(self,rml, localcontext = None, logo=None, title=None):
|
||||
obj = render.odt2odt(etree.XML(rml),localcontext)
|
||||
obj.render()
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from lxml import etree
|
||||
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']
|
||||
|
||||
class report(object):
|
||||
|
@ -36,6 +37,8 @@ class report(object):
|
|||
match = rml_parents
|
||||
if type in ['odt','sxw']:
|
||||
match = sxw_parents
|
||||
if type =='html2html':
|
||||
match = html_parents
|
||||
if txt.group(3):
|
||||
match = [txt.group(3)]
|
||||
n = node
|
||||
|
|
|
@ -21,8 +21,7 @@
|
|||
##############################################################################
|
||||
|
||||
from simple import simple
|
||||
from rml import rml, rml2html, odt2odt
|
||||
|
||||
from rml import rml, rml2html, odt2odt , html2html
|
||||
from render import render
|
||||
|
||||
try:
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
|
||||
# $Id$
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from html2html import parseString
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
|
||||
# $Id$
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from report.render.rml2pdf import utils
|
||||
from lxml import etree
|
||||
import copy
|
||||
import pooler
|
||||
|
||||
|
||||
class html2html(object):
|
||||
def __init__(self, html, localcontext):
|
||||
self.localcontext = localcontext
|
||||
self.etree = html
|
||||
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.remove(n)
|
||||
process_text(child, new_child)
|
||||
else:
|
||||
if new_child.tag=='img' and new_child.get('name'):
|
||||
src = utils._process_text(self, new_child.get('name'))
|
||||
if src :
|
||||
new_child.set('src','data:image/gif;base64,%s'%src)
|
||||
new_child.text = utils._process_text(self, child.text)
|
||||
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 parseString(node, localcontext = {}):
|
||||
r = html2html(node, localcontext)
|
||||
return r.render()
|
||||
|
|
@ -24,6 +24,7 @@ import render
|
|||
import rml2pdf
|
||||
import rml2html as htmlizer
|
||||
import odt2odt as odt
|
||||
import html2html as html
|
||||
|
||||
|
||||
class rml(render.render):
|
||||
|
@ -60,5 +61,15 @@ class odt2odt(render.render):
|
|||
def _render(self):
|
||||
return odt.parseNode(self.rml_dom,self.localcontext)
|
||||
|
||||
class html2html(render.render):
|
||||
def __init__(self, rml, localcontext = None, datas = {}):
|
||||
render.render.__init__(self, datas)
|
||||
self.rml_dom = rml
|
||||
self.localcontext = localcontext
|
||||
self.output_type = 'html'
|
||||
|
||||
def _render(self):
|
||||
return html.parseString(self.rml_dom,self.localcontext)
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -61,6 +61,11 @@ sxw_parents = {
|
|||
'section': 0,
|
||||
}
|
||||
|
||||
html_parents = {
|
||||
'tr' : 1,
|
||||
'body' : 0,
|
||||
'div' : 0
|
||||
}
|
||||
sxw_tag = "p"
|
||||
|
||||
rml2sxw = {
|
||||
|
@ -166,6 +171,7 @@ class rml_parse(object):
|
|||
'logo' : user.company_id.logo,
|
||||
'lang' : user.company_id.partner_id.lang,
|
||||
'translate' : self._translate,
|
||||
'setHtmlImage' : self.set_html_image
|
||||
}
|
||||
self.localcontext.update(context)
|
||||
self.rml_header = user.company_id.rml_header
|
||||
|
@ -190,6 +196,17 @@ class rml_parse(object):
|
|||
def removeParentNode(self, tag=None):
|
||||
raise Exception('Skip')
|
||||
|
||||
def set_html_image(self,attach_id):
|
||||
try :
|
||||
att_id = int(attach_id)
|
||||
print att_id
|
||||
attachment = self.pool.get('ir.attachment').browse(self.cr,self.uid,att_id)
|
||||
print attachment
|
||||
print attachment.datas
|
||||
return attachment.datas
|
||||
except :
|
||||
return ''
|
||||
|
||||
def setLang(self, lang):
|
||||
if not lang or self.default_lang.has_key(lang):
|
||||
if not lang:
|
||||
|
@ -342,8 +359,10 @@ class report_sxw(report_rml, preprocess.report):
|
|||
report_type = report_xml.report_type
|
||||
if report_type in ['sxw','odt']:
|
||||
fnct = self.create_source_odt
|
||||
elif report_type in ['pdf','html','raw']:
|
||||
elif report_type in ['pdf','raw','html']:
|
||||
fnct = self.create_source_pdf
|
||||
elif report_type=='html2html':
|
||||
fnct = self.create_source_html2html
|
||||
else:
|
||||
raise 'Unknown Report Type'
|
||||
return fnct(cr, uid, ids, data, report_xml, context)
|
||||
|
@ -351,6 +370,9 @@ class report_sxw(report_rml, preprocess.report):
|
|||
def create_source_odt(self, cr, uid, ids, data, report_xml, context=None):
|
||||
return self.create_single_odt(cr, uid, ids, data, report_xml, context or {})
|
||||
|
||||
def create_source_html2html(self, cr, uid, ids, data, report_xml, context=None):
|
||||
return self.create_single_html2html(cr, uid, ids, data, report_xml, context or {})
|
||||
|
||||
def create_source_pdf(self, cr, uid, ids, data, report_xml, context=None):
|
||||
if not context:
|
||||
context={}
|
||||
|
@ -476,5 +498,26 @@ class report_sxw(report_rml, preprocess.report):
|
|||
final_op = sxw_io.getvalue()
|
||||
sxw_io.close()
|
||||
return (final_op, report_type)
|
||||
|
||||
def create_single_html2html(self, cr, uid, ids, data, report_xml, context={}):
|
||||
context = context.copy()
|
||||
report_type = 'html'
|
||||
context['parents'] = html_parents
|
||||
|
||||
rml = report_xml.report_rml_content
|
||||
|
||||
rml_parser = self.parser(cr, uid, self.name2, context)
|
||||
rml_parser.parents = html_parents
|
||||
rml_parser.tag = sxw_tag
|
||||
objs = self.getObjects(cr, uid, ids, context)
|
||||
rml_parser.set_context(objs, data, ids, report_type)
|
||||
|
||||
rml_dom = etree.HTML(rml)
|
||||
rml_dom = self.preprocess_rml(rml_dom,'html2html')
|
||||
create_doc = self.generators['html2html']
|
||||
html = etree.tostring(create_doc(rml_dom, rml_parser.localcontext))
|
||||
|
||||
return (html, report_type)
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue