1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
23
from lxml import etree
24
from mako.template import Template
25
from mako.lookup import TemplateLookup
28
_logger = logging.getLogger(__name__)
30
class makohtml2html(object):
31
def __init__(self, html, localcontext):
32
self.localcontext = localcontext
35
def format_header(self, html):
36
head = html.findall('head')
39
header += etree.tostring(node)
42
def format_footer(self, footer):
44
for node in footer[0].getchildren():
45
html_footer += etree.tostring(node)
48
def format_body(self, html):
49
body = html.findall('body')
51
footer = self.format_footer(body[-1].getchildren())
53
body_list.append(etree.tostring(b).replace('\t', '').replace('\n',''))
55
<script type="text/javascript">
61
if(indexer < aryTest.length -1)
64
document.forms[0].prev.disabled = false;
65
document.getElementById("openerp_data").innerHTML=aryTest[indexer];
66
document.getElementById("counter").innerHTML= indexer + 1 + ' / ' + aryTest.length;
70
document.forms[0].next.disabled = true;
78
document.forms[0].next.disabled = false;
79
document.getElementById("openerp_data").innerHTML=aryTest[indexer];
80
document.getElementById("counter").innerHTML= indexer + 1 + ' / ' + aryTest.length;
84
document.forms[0].prev.disabled = true;
90
<div id="openerp_data">
101
<input name = "prev" type="button" value="Previous" onclick="prevData();">
104
<div id = "counter">%s / %s</div>
107
<input name = "next" type="button" value="Next" onclick="nextData();">
112
</body></html>'''%(body_list,body_list[0],footer,'1',len(body_list))
116
path = os.path.realpath('addons/base/report')
117
temp_lookup = TemplateLookup(directories=[path],output_encoding='utf-8', encoding_errors='replace')
118
template = Template(self.html, lookup=temp_lookup)
119
self.localcontext.update({'css_path':path})
120
final_html ='''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
123
html = template.render_unicode(**self.localcontext)
124
etree_obj = etree.HTML(html)
125
final_html += self.format_header(etree_obj)
126
final_html += self.format_body(etree_obj)
129
_logger.exception('report :')
131
def parseNode(html, localcontext = {}):
132
r = makohtml2html(html, localcontext)
135
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: