Browse Source

Restore direct rendering for native ODT output formats

--HG--
branch : odoo8
pull/80/head
Jérémie Gavrel 9 years ago
parent
commit
49defabe88
  1. 13
      models/py3o_template.py
  2. 90
      py3o_parser.py
  3. 2
      views/py3o_template.xml

13
models/py3o_template.py

@ -8,7 +8,20 @@ class py3o_template(osv.Model):
'name': fields.char(
u"Name",
),
'py3o_template_data': fields.binary(
u"LibreOffice template",
),
'filetype': fields.selection(
[
('odt', u"ODF Text Document"),
('ods', u"ODF Spreadsheet"),
],
u"LibreOffice Template File Type",
),
}
_defaults = {
'filetype': 'odt'
}

90
py3o_parser.py

@ -154,50 +154,58 @@ class Py3oParser(report_sxw):
datadict = parser_instance.localcontext
res = data_struct.render(datadict)
parsed_datadict = data_struct.render(datadict)
fusion_server_obj = pool.get('py3o.server')
fusion_server_ids = fusion_server_obj.search(
cr, uid, [], context=context
)
if not fusion_server_ids:
raise exceptions.MissingError(
_(u"No Py3o server configuration found")
)
fusion_server_id = fusion_server_ids[0]
if filetype.fusion_ext == report_xml.py3o_template_id.filetype:
# No format conversion is needed, render the template directly
template.render(parsed_datadict)
res = out_stream.getvalue()
fusion_server = fusion_server_obj.browse(
cr, uid, fusion_server_id, context=context
)
in_stream.seek(0)
files = {
'tmpl_file': in_stream,
}
fields = {
"targetformat": filetype.fusion_ext,
"datadict": json.dumps(res),
"image_mapping": "{}",
}
r = requests.post(fusion_server.url, data=fields, files=files)
if r.status_code != 200:
# server says we have an issue... let's tell that to enduser
raise exceptions.Warning(
_('Fusion server error'),
r.text,
else: # Call py3o.server to render the template in the desired format
fusion_server_obj = pool.get('py3o.server')
fusion_server_ids = fusion_server_obj.search(
cr, uid, [], context=context
)
# Here is a little joke about Odoo
# we do nice chunked reading from the network...
chunk_size = 1024
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
if not fusion_server_ids:
raise exceptions.MissingError(
_(u"No Py3o server configuration found")
)
fusion_server_id = fusion_server_ids[0]
fusion_server = fusion_server_obj.browse(
cr, uid, fusion_server_id, context=context
)
in_stream.seek(0)
files = {
'tmpl_file': in_stream,
}
fields = {
"targetformat": filetype.fusion_ext,
"datadict": json.dumps(parsed_datadict),
"image_mapping": "{}",
}
r = requests.post(fusion_server.url, data=fields, files=files)
if r.status_code != 200:
# server says we have an issue... let's tell that to enduser
raise exceptions.Warning(
_('Fusion server error'),
r.text,
)
# Here is a little joke about Odoo
# we do nice chunked reading from the network...
chunk_size = 1024
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 :)
res = fd.read()
return res, filetype.human_ext
def create(self, cr, uid, ids, data, context=None):
""" Override this function to handle our py3o report

2
views/py3o_template.xml

@ -9,6 +9,7 @@
<sheet>
<group>
<field name="name" />
<field name="filetype" />
<field name="py3o_template_data" />
</group>
</sheet>
@ -22,6 +23,7 @@
<field name="arch" type="xml">
<tree string="Py3o Templates Configuration" version="7.0">
<field name="name" />
<field name="filetype" />
</tree>
</field>
</record>

Loading…
Cancel
Save