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
26 import openerp.netsvc as netsvc
27 import traceback, sys, os
29 _logger = logging.getLogger(__name__)
31 class makohtml2html(object):
32 def __init__(self, html, localcontext):
33 self.localcontext = localcontext
36 def format_header(self, html):
37 head = html.findall('head')
40 header += etree.tostring(node)
43 def format_footer(self, footer):
45 for node in footer[0].getchildren():
46 html_footer += etree.tostring(node)
49 def format_body(self, html):
50 body = html.findall('body')
52 footer = self.format_footer(body[-1].getchildren())
54 body_list.append(etree.tostring(b).replace('\t', '').replace('\n',''))
56 <script type="text/javascript">
62 if(indexer < aryTest.length -1)
65 document.forms[0].prev.disabled = false;
66 document.getElementById("openerp_data").innerHTML=aryTest[indexer];
67 document.getElementById("counter").innerHTML= indexer + 1 + ' / ' + aryTest.length;
71 document.forms[0].next.disabled = true;
79 document.forms[0].next.disabled = false;
80 document.getElementById("openerp_data").innerHTML=aryTest[indexer];
81 document.getElementById("counter").innerHTML= indexer + 1 + ' / ' + aryTest.length;
85 document.forms[0].prev.disabled = true;
91 <div id="openerp_data">
102 <input name = "prev" type="button" value="Previous" onclick="prevData();">
105 <div id = "counter">%s / %s</div>
108 <input name = "next" type="button" value="Next" onclick="nextData();">
113 </body></html>'''%(body_list,body_list[0],footer,'1',len(body_list))
117 path = os.path.realpath('addons/base/report')
118 temp_lookup = TemplateLookup(directories=[path],output_encoding='utf-8', encoding_errors='replace')
119 template = Template(self.html, lookup=temp_lookup)
120 self.localcontext.update({'css_path':path})
121 final_html ='''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
124 html = template.render_unicode(**self.localcontext)
125 etree_obj = etree.HTML(html)
126 final_html += self.format_header(etree_obj)
127 final_html += self.format_body(etree_obj)
130 tb_s = reduce(lambda x, y: x+y, traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
131 _logger.error('report :\n%s\n%s\n', tb_s, str(e))
133 def parseNode(html, localcontext = {}):
134 r = makohtml2html(html, localcontext)
137 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: