2009-11-02 09:15:24 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2009-10-30 12:33:59 +00:00
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
2009-11-02 09:15:24 +00:00
|
|
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
2009-10-30 12:33:59 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-11-02 09:15:24 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2009-10-30 12:33:59 +00:00
|
|
|
#
|
|
|
|
# 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
|
2009-11-02 09:15:24 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2009-10-30 12:33:59 +00:00
|
|
|
#
|
2009-11-02 09:15:24 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2009-10-30 12:33:59 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
2009-12-15 05:22:39 +00:00
|
|
|
import mako
|
2009-10-30 12:33:59 +00:00
|
|
|
from lxml import etree
|
|
|
|
from mako.template import Template
|
|
|
|
from mako.lookup import TemplateLookup
|
2011-02-07 12:57:23 +00:00
|
|
|
import openerp.netsvc as netsvc
|
2009-10-30 12:33:59 +00:00
|
|
|
import traceback, sys, os
|
|
|
|
|
|
|
|
class makohtml2html(object):
|
|
|
|
def __init__(self, html, localcontext):
|
|
|
|
self.localcontext = localcontext
|
|
|
|
self.html = html
|
|
|
|
|
|
|
|
def format_header(self, html):
|
|
|
|
head = html.findall('head')
|
|
|
|
header = ''
|
|
|
|
for node in head:
|
|
|
|
header += etree.tostring(node)
|
|
|
|
return header
|
|
|
|
|
|
|
|
def format_footer(self, footer):
|
|
|
|
html_footer = ''
|
|
|
|
for node in footer[0].getchildren():
|
|
|
|
html_footer += etree.tostring(node)
|
|
|
|
return html_footer
|
|
|
|
|
|
|
|
def format_body(self, html):
|
|
|
|
body = html.findall('body')
|
|
|
|
body_list = []
|
|
|
|
footer = self.format_footer(body[-1].getchildren())
|
|
|
|
for b in body[:-1]:
|
2009-10-30 12:38:11 +00:00
|
|
|
body_list.append(etree.tostring(b).replace('\t', '').replace('\n',''))
|
2009-10-30 12:33:59 +00:00
|
|
|
html_body ='''
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
var indexer = 0;
|
|
|
|
var aryTest = %s ;
|
|
|
|
function nextData()
|
|
|
|
{
|
|
|
|
if(indexer < aryTest.length -1)
|
|
|
|
{
|
|
|
|
indexer += 1;
|
2009-11-02 05:50:06 +00:00
|
|
|
document.forms[0].prev.disabled = false;
|
2009-10-30 12:33:59 +00:00
|
|
|
document.getElementById("openerp_data").innerHTML=aryTest[indexer];
|
2009-11-02 05:50:06 +00:00
|
|
|
document.getElementById("counter").innerHTML= indexer + 1 + ' / ' + aryTest.length;
|
2009-10-30 12:33:59 +00:00
|
|
|
}
|
2009-11-02 05:50:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
document.forms[0].next.disabled = true;
|
|
|
|
}
|
2009-10-30 12:33:59 +00:00
|
|
|
}
|
|
|
|
function prevData()
|
|
|
|
{
|
|
|
|
if (indexer > 0)
|
|
|
|
{
|
|
|
|
indexer -= 1;
|
2009-11-02 05:50:06 +00:00
|
|
|
document.forms[0].next.disabled = false;
|
2009-10-30 12:33:59 +00:00
|
|
|
document.getElementById("openerp_data").innerHTML=aryTest[indexer];
|
2009-11-02 05:50:06 +00:00
|
|
|
document.getElementById("counter").innerHTML= indexer + 1 + ' / ' + aryTest.length;
|
2009-10-30 12:33:59 +00:00
|
|
|
}
|
2009-11-02 05:50:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
document.forms[0].prev.disabled = true;
|
|
|
|
}
|
2009-10-30 12:33:59 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="openerp_data">
|
|
|
|
%s
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
%s
|
|
|
|
</div>
|
|
|
|
<br>
|
2009-11-02 05:50:06 +00:00
|
|
|
<form>
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<td td align="left">
|
|
|
|
<input name = "prev" type="button" value="Previous" onclick="prevData();">
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<div id = "counter">%s / %s</div>
|
|
|
|
</td>
|
|
|
|
<td align="right">
|
|
|
|
<input name = "next" type="button" value="Next" onclick="nextData();">
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</form>
|
|
|
|
</body></html>'''%(body_list,body_list[0],footer,'1',len(body_list))
|
2009-10-30 12:33:59 +00:00
|
|
|
return html_body
|
|
|
|
|
|
|
|
def render(self):
|
|
|
|
path = os.path.realpath('addons/base/report')
|
|
|
|
temp_lookup = TemplateLookup(directories=[path],output_encoding='utf-8', encoding_errors='replace')
|
|
|
|
template = Template(self.html, lookup=temp_lookup)
|
|
|
|
self.localcontext.update({'css_path':path})
|
|
|
|
final_html ='''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
|
|
<html>'''
|
|
|
|
try:
|
|
|
|
html = template.render_unicode(**self.localcontext)
|
|
|
|
etree_obj = etree.HTML(html)
|
|
|
|
final_html += self.format_header(etree_obj)
|
|
|
|
final_html += self.format_body(etree_obj)
|
|
|
|
return final_html
|
|
|
|
except Exception,e:
|
|
|
|
tb_s = reduce(lambda x, y: x+y, traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
|
|
|
|
netsvc.Logger().notifyChannel('report', netsvc.LOG_ERROR,
|
|
|
|
'report :\n%s\n%s\n' % (tb_s, str(e)))
|
|
|
|
|
|
|
|
def parseNode(html, localcontext = {}):
|
|
|
|
r = makohtml2html(html, localcontext)
|
2011-02-07 12:57:23 +00:00
|
|
|
return r.render()
|
2011-11-22 08:58:48 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|