[IMP] Add the possiblity to get the template from an absolute path on the server
parent
9aa0227c52
commit
a4cea21ecc
|
@ -38,7 +38,8 @@ class ReportXml(models.Model):
|
||||||
size=128,
|
size=128,
|
||||||
help=(
|
help=(
|
||||||
"If the user does not provide a template this will be used "
|
"If the user does not provide a template this will be used "
|
||||||
"it should be a relative path to root of YOUR module"
|
"it should be a relative path to root of YOUR module "
|
||||||
|
"or an absolute path on your server."
|
||||||
))
|
))
|
||||||
report_type = fields.Selection(selection_add=[('py3o', "Py3o")])
|
report_type = fields.Selection(selection_add=[('py3o', "Py3o")])
|
||||||
|
|
||||||
|
|
|
@ -88,16 +88,22 @@ class Py3oParser(report_sxw):
|
||||||
report_obj.py3o_template_id.py3o_template_data
|
report_obj.py3o_template_id.py3o_template_data
|
||||||
)
|
)
|
||||||
|
|
||||||
elif report_obj.py3o_template_fallback and report_obj.module:
|
elif report_obj.py3o_template_fallback:
|
||||||
# if the default is defined
|
tmpl_name = report_obj.py3o_template_fallback
|
||||||
flbk_filename = pkg_resources.resource_filename(
|
flbk_filename = None
|
||||||
"openerp.addons.%s" % report_obj.module,
|
if report_obj.module:
|
||||||
report_obj.py3o_template_fallback,
|
# if the default is defined
|
||||||
)
|
flbk_filename = pkg_resources.resource_filename(
|
||||||
if os.path.exists(flbk_filename):
|
"openerp.addons.%s" % report_obj.module,
|
||||||
# and it exists on the fileystem
|
tmpl_name,
|
||||||
with open(flbk_filename, 'r') as tmpl:
|
)
|
||||||
tmpl_data = tmpl.read()
|
elif os.path.isabs(tmpl_name):
|
||||||
|
# It is an absolute path
|
||||||
|
flbk_filename = os.path.normcase(os.path.normpath(tmpl_name))
|
||||||
|
if flbk_filename and os.path.exists(flbk_filename):
|
||||||
|
# and it exists on the fileystem
|
||||||
|
with open(flbk_filename, 'r') as tmpl:
|
||||||
|
tmpl_data = tmpl.read()
|
||||||
|
|
||||||
if tmpl_data is None:
|
if tmpl_data is None:
|
||||||
# if for any reason the template is not found
|
# if for any reason the template is not found
|
||||||
|
|
Loading…
Reference in New Issue