Merge pull request #203 from edufresne/master

Fix need to "Recover document" after using replace_media and saving to file-like object
This commit is contained in:
Eric Lapouyade 2019-06-05 09:06:30 +02:00 committed by GitHub
commit 9f1cb53205
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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())