Provide better support for file-like objects with replace-media

This commit is contained in:
ericdufresne 2019-06-03 11:34:16 -04:00
parent a021c517f5
commit fbb930d3ea
2 changed files with 5 additions and 2 deletions

View File

@ -456,8 +456,9 @@ class DocxTemplate(object):
if hasattr(docx_file, 'read'):
tmp_file = io.BytesIO()
Document(docx_file).save(tmp_file)
DocxTemplate(docx_file).save(tmp_file)
tmp_file.seek(0)
docx_file.seek(0)
else:
tmp_file = '%s_docxtpl_before_replace_medias' % docx_file

View File

@ -32,4 +32,6 @@ tpl.render(context)
file_obj = io.BytesIO()
tpl.save(file_obj)
file_obj.seek(0)
DocxTemplate(file_obj).save(DEST_FILE2)
with open(DEST_FILE2, 'wb') as f:
f.write(file_obj.read())