Now support latest fusion server & better error reporting

--HG--
branch : odoo8
pull/80/head
Florent Aide 2015-06-04 00:52:59 +02:00
parent f71cbbb92d
commit 1dee92362f
2 changed files with 30 additions and 20 deletions

View File

@ -1,6 +1,6 @@
id,fusion_ext,human_ext id,fusion_ext,human_ext
py3o_fusion_filetype_odt,ODT,odt py3o_fusion_filetype_odt,odt,odt
py3o_fusion_filetype_ods,ODS,ods py3o_fusion_filetype_ods,ods,ods
py3o_fusion_filetype_doc,DOC,doc py3o_fusion_filetype_doc,doc,doc
py3o_fusion_filetype_docx,DOCX,docx py3o_fusion_filetype_docx,docx,docx
py3o_fusion_filetype_pdf,PDF,pdf py3o_fusion_filetype_pdf,pdf,pdf

1 id fusion_ext human_ext
2 py3o_fusion_filetype_odt ODT odt odt
3 py3o_fusion_filetype_ods ODS ods ods
4 py3o_fusion_filetype_doc DOC doc doc
5 py3o_fusion_filetype_docx DOCX docx docx
6 py3o_fusion_filetype_pdf PDF pdf pdf

View File

@ -8,7 +8,7 @@ from tempfile import NamedTemporaryFile
from openerp import _ from openerp import _
from openerp.report.report_sxw import report_sxw, rml_parse from openerp.report.report_sxw import report_sxw, rml_parse
from openerp import registry from openerp import registry
from openerp.exceptions import DeferredException from openerp.exceptions import ValidationError
from py3o.template import Template from py3o.template import Template
@ -16,7 +16,7 @@ from py3o.template import Template
_extender_functions = {} _extender_functions = {}
class TemplateNotFound(DeferredException): class TemplateNotFound(Exception):
pass pass
@ -96,10 +96,6 @@ class Py3oParser(report_sxw):
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
print("*"*35)
print("Template filename: %s" % flbk_filename)
print("*"*35)
raise TemplateNotFound( raise TemplateNotFound(
_(u'No template found. Aborting.'), _(u'No template found. Aborting.'),
sys.exc_info(), sys.exc_info(),
@ -160,6 +156,10 @@ class Py3oParser(report_sxw):
out_temp.seek(0) out_temp.seek(0)
# TODO: use py3o.formats to know native formats instead
# of hardcoding this value
# TODO: why use the human readable form when you're a machine?
# this is non-sense AND dangerous... please use technical name
if filetype.human_ext != 'odt': if filetype.human_ext != 'odt':
# Now we ask fusion server to convert our template # Now we ask fusion server to convert our template
fusion_server_obj = pool['py3o.server'] fusion_server_obj = pool['py3o.server']
@ -178,16 +178,26 @@ class Py3oParser(report_sxw):
"image_mapping": "{}", "image_mapping": "{}",
"skipfusion": True, "skipfusion": True,
} }
# Here is a little joke about Odoo
# we do nice chunked reading from the network...
r = requests.post(fusion_server.url, data=fields, files=files) r = requests.post(fusion_server.url, data=fields, files=files)
chunk_size = 1024 if r.status_code == 400:
with NamedTemporaryFile( # server says we have an issue... let's to that
suffix=filetype.human_ext, raise ValidationError(
prefix='py3o-template-' r.json(),
) as fd: )
for chunk in r.iter_content(chunk_size):
fd.write(chunk) else:
fd.seek(0) chunk_size = 1024
return fd.read(), filetype.human_ext with NamedTemporaryFile(
suffix=filetype.human_ext,
prefix='py3o-template-'
) as fd:
for chunk in r.iter_content(chunk_size):
fd.write(chunk)
fd.seek(0)
# ... but odoo wants the whole data in memory anyways :)
return fd.read(), filetype.human_ext
return out_temp.read(), 'odt' return out_temp.read(), 'odt'