[MERGE] merged webkit fixes (mainly UTF8), courtesy of Nicolas Bessi, C2C

bzr revid: odo@openerp.com-20110430014750-ycfmrsr4jw80p7uy
This commit is contained in:
Olivier Dony
2011-04-30 03:47:50 +02:00
4 changed files with 25 additions and 11 deletions
+2 -2
View File
@@ -53,7 +53,7 @@
<body style="border:0; margin: 0;" onload="subst()">
<table class="header" style="border-bottom: 0px solid black; width: 100%">
<tr>
<td>${helper.embed_logo_by_name('camptocamp_logo')}</td>
<td>${helper.embed_logo_by_name('camptocamp_logo')|n}</td>
<td style="text-align:right"> </td>
</tr>
<tr>
@@ -75,7 +75,7 @@
<tr>
<td>Mail: ${company.partner_id.address and company.partner_id.address[0].email or ''|entity}<br/></td>
</tr>
</table> ${_debug or ''} </body>
</table> ${_debug or ''|n} </body>
</html>]]>
</field>
<field eval="55.0" name="margin_top"/>
+2 -2
View File
@@ -49,7 +49,7 @@
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem action="action_header_img" id="menu_header_img" parent="base.menu_action_res_company_tree" sequence="14"/>
<menuitem action="action_header_img" id="menu_header_img" parent="base.menu_action_res_company_form" sequence="14"/>
<record id="action_header_webkit" model="ir.actions.act_window">
<field name="name">Header HTML</field>
@@ -57,7 +57,7 @@
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem action="action_header_webkit" id="menu_header_webkit" parent="base.menu_action_res_company_tree" sequence="14"/>
<menuitem action="action_header_webkit" id="menu_header_webkit" parent="base.menu_action_res_company_form" sequence="14"/>
</data>
+1 -1
View File
@@ -48,7 +48,7 @@ class WebKitHelper(object):
else :
width = ' '
if height :
height = 'width="%spx"'%(height)
height = 'height="%spx"'%(height)
else :
height = ' '
toreturn = '<img %s %s src="data:image/%s;base64,%s" />'%(
+20 -6
View File
@@ -5,6 +5,7 @@
# All Right Reserved
#
# Author : Nicolas Bessi (Camptocamp)
# Contributor(s) : Florent Xicluna (Wingo SA)
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
@@ -44,6 +45,16 @@ import addons
from tools.translate import _
from osv.osv import except_osv
def mako_template(text):
"""Build a Mako template.
This template uses UTF-8 encoding
"""
# default_filters=['unicode', 'h'] can be used to set global filters
return Template(text, input_encoding='utf-8', output_encoding='utf-8')
class WebKitParser(report_sxw):
"""Custom class that use webkit to render HTML reports
Code partially taken from report openoffice. Thanks guys :)
@@ -67,7 +78,8 @@ class WebKitParser(report_sxw):
_('Please install executable on your system'+
' (sudo apt-get install wkhtmltopdf) or download it from here:'+
' http://code.google.com/p/wkhtmltopdf/downloads/list and set the'+
' path to the executable on the Company form.')
' path to the executable on the Company form.'+
'Minimal version is 0.9.9')
)
if os.path.isabs(path) :
if (os.path.exists(path) and os.access(path, os.X_OK)\
@@ -98,7 +110,9 @@ class WebKitParser(report_sxw):
else:
command = ['wkhtmltopdf']
command.append('-q')
command.append('--quiet')
# default to UTF-8 encoding. Use <meta charset="latin-1"> to override.
command.extend(['--encoding', 'utf-8'])
if header :
head_file = file( os.path.join(
tmp_dir,
@@ -276,7 +290,7 @@ class WebKitParser(report_sxw):
company= user.company_id
#default_filters=['unicode', 'entity'] can be used to set global filter
body_mako_tpl = Template(template ,input_encoding='utf-8')
body_mako_tpl = mako_template(template)
helper = WebKitHelper(cursor, uid, report_xml.id, context)
try :
html = body_mako_tpl.render( helper=helper,
@@ -288,7 +302,7 @@ class WebKitParser(report_sxw):
msg = exceptions.text_error_template().render()
netsvc.Logger().notifyChannel('Webkit render', netsvc.LOG_ERROR, msg)
raise except_osv(_('Webkit render'), msg)
head_mako_tpl = Template(header, input_encoding='utf-8')
head_mako_tpl = mako_template(header)
try :
head = head_mako_tpl.render(
company=company,
@@ -305,7 +319,7 @@ class WebKitParser(report_sxw):
exceptions.text_error_template().render())
foot = False
if footer :
foot_mako_tpl = Template(footer ,input_encoding='utf-8')
foot_mako_tpl = mako_template(footer)
try :
foot = foot_mako_tpl.render(
company=company,
@@ -327,7 +341,7 @@ class WebKitParser(report_sxw):
time=time,
helper=helper,
css=css,
_debug=html,
_debug=html.decode(),
formatLang=self.formatLang,
setLang=self.setLang,
_=self.translate_call,