[FIX] webkit: User friendly popup error message displayed when webkit report's path does not exist.

lp bug: https://launchpad.net/bugs/747284 fixed

bzr revid: rch@tinyerp.com-20110613111747-nh9j1t8kfss2o8vu
This commit is contained in:
rch-openerp
2011-06-13 16:47:47 +05:30
parent c53a71e5fd
commit ba16e35fef
+22 -22
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com)
# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com)
# All Right Reserved
#
# Author : Nicolas Bessi (Camptocamp)
@@ -60,12 +60,12 @@ class WebKitParser(report_sxw):
"""Custom class that use webkit to render HTML reports
Code partially taken from report openoffice. Thanks guys :)
"""
def __init__(self, name, table, rml=False, parser=False,
def __init__(self, name, table, rml=False, parser=False,
header=True, store=False):
self.parser_instance = False
self.localcontext={}
report_sxw.__init__(self, name, table, rml, parser,
report_sxw.__init__(self, name, table, rml, parser,
header, store)
def get_lib(self, cursor, uid, company) :
@@ -81,7 +81,7 @@ class WebKitParser(report_sxw):
' http://code.google.com/p/wkhtmltopdf/downloads/list and set the'+
' 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)\
and os.path.basename(path).startswith('wkhtmltopdf')):
@@ -118,7 +118,7 @@ class WebKitParser(report_sxw):
head_file = file( os.path.join(
tmp_dir,
str(time.time()) + '.head.html'
),
),
'w'
)
head_file.write(header)
@@ -129,14 +129,14 @@ class WebKitParser(report_sxw):
foot_file = file( os.path.join(
tmp_dir,
str(time.time()) + '.foot.html'
),
),
'w'
)
foot_file.write(footer)
foot_file.close()
file_to_del.append(foot_file.name)
command.extend(['--footer-html', foot_file.name])
if webkit_header.margin_top :
command.extend(['--margin-top', str(webkit_header.margin_top).replace(',', '.')])
if webkit_header.margin_bottom :
@@ -163,7 +163,7 @@ class WebKitParser(report_sxw):
status = subprocess.call(command, stderr=subprocess.PIPE) # ignore stderr
if status :
raise except_osv(
_('Webkit raise an error' ),
_('Webkit raise an error' ),
status
)
except Exception:
@@ -176,8 +176,8 @@ class WebKitParser(report_sxw):
os.unlink(out)
return pdf
def setLang(self, lang):
if not lang:
lang = 'en_US'
@@ -189,8 +189,8 @@ class WebKitParser(report_sxw):
res = ir_translation._get_source(self.parser_instance.cr, self.parser_instance.uid, self.name, 'report', self.localcontext.get('lang', 'en_US'), src)
if not res :
return src
return res
return res
def formatLang(self, value, digits=None, date=False, date_time=False, grouping=True, monetary=False):
"""format using the know cursor, language from localcontext"""
if digits is None:
@@ -199,7 +199,7 @@ class WebKitParser(report_sxw):
return ''
pool_lang = self.pool.get('res.lang')
lang = self.localcontext['lang']
lang_ids = pool_lang.search(self.parser_instance.cr, self.parser_instance.uid, [('code','=',lang)])[0]
lang_obj = pool_lang.browse(self.parser_instance.cr, self.parser_instance.uid, lang_ids)
@@ -225,7 +225,7 @@ class WebKitParser(report_sxw):
# override needed to keep the attachments' storing procedure
def create_single_pdf(self, cursor, uid, ids, data, report_xml, context=None):
"""generate the PDF"""
if context is None:
context={}
@@ -247,7 +247,7 @@ class WebKitParser(report_sxw):
if report_xml.report_file :
path = addons.get_module_resource(report_xml.report_file)
if os.path.exists(path) :
if path and os.path.exists(path) :
template = file(path).read()
if not template and report_xml.report_webkit_data :
template = report_xml.report_webkit_data
@@ -266,7 +266,7 @@ class WebKitParser(report_sxw):
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
<style type="text/css">
<style type="text/css">
${css}
</style>
<script>
@@ -290,7 +290,7 @@ class WebKitParser(report_sxw):
css = ''
user = self.pool.get('res.users').browse(cursor, uid, uid)
company= user.company_id
#default_filters=['unicode', 'entity'] can be used to set global filter
body_mako_tpl = mako_template(template)
helper = WebKitHelper(cursor, uid, report_xml.id, context)
@@ -366,11 +366,11 @@ class WebKitParser(report_sxw):
report_xml_ids = ir_obj.search(cursor, uid,
[('report_name', '=', self.name[7:])], context=context)
if report_xml_ids:
report_xml = ir_obj.browse(
cursor,
uid,
report_xml_ids[0],
cursor,
uid,
report_xml_ids[0],
context=context
)
report_xml.report_rml = None