_pack_document() method changed. ODT files have to start mimetype with non-zipped
This commit is contained in:
parent
d132c2a98c
commit
cf7489a1c0
1 changed files with 8 additions and 1 deletions
|
|
@ -177,7 +177,13 @@ class Renderer(object):
|
||||||
self.log.debug('packing document')
|
self.log.debug('packing document')
|
||||||
zip_file = io.BytesIO()
|
zip_file = io.BytesIO()
|
||||||
|
|
||||||
|
mimetype = files['mimetype']
|
||||||
|
del files['mimetype']
|
||||||
|
|
||||||
zipdoc = zipfile.ZipFile(zip_file, 'a')
|
zipdoc = zipfile.ZipFile(zip_file, 'a')
|
||||||
|
|
||||||
|
zipdoc.writestr('mimetype', mimetype, zipfile.ZIP_STORED)
|
||||||
|
|
||||||
for fname, content in files.items():
|
for fname, content in files.items():
|
||||||
if sys.version_info >= (2, 7):
|
if sys.version_info >= (2, 7):
|
||||||
zipdoc.writestr(fname, content, zipfile.ZIP_DEFLATED)
|
zipdoc.writestr(fname, content, zipfile.ZIP_DEFLATED)
|
||||||
|
|
@ -572,6 +578,7 @@ class Renderer(object):
|
||||||
if not 'result' in locals():
|
if not 'result' in locals():
|
||||||
result = xml_source
|
result = xml_source
|
||||||
near = result.split('\n')[e.lineno -1][e.offset-200:e.offset+200]
|
near = result.split('\n')[e.lineno -1][e.offset-200:e.offset+200]
|
||||||
|
|
||||||
raise ExpatError('ExpatError "%s" at line %d, column %d\nNear of: "[...]%s[...]"' % \
|
raise ExpatError('ExpatError "%s" at line %d, column %d\nNear of: "[...]%s[...]"' % \
|
||||||
(ErrorString(e.code), e.lineno, e.offset, near))
|
(ErrorString(e.code), e.lineno, e.offset, near))
|
||||||
except:
|
except:
|
||||||
|
|
@ -846,7 +853,7 @@ if __name__ == "__main__":
|
||||||
]
|
]
|
||||||
|
|
||||||
render = Renderer()
|
render = Renderer()
|
||||||
result = render.render('simple_template.odt', countries=countries, document=document)
|
result = render.render('simple_template2.odt', countries=countries, document=document)
|
||||||
|
|
||||||
output = open('rendered.odt', 'wb')
|
output = open('rendered.odt', 'wb')
|
||||||
output.write(result)
|
output.write(result)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue