This commit is contained in:
elapouya 2023-01-07 14:02:11 +01:00
parent ce23f81cbe
commit ef09ce6277
5 changed files with 25 additions and 7 deletions

View File

@ -1,3 +1,9 @@
0.16.5 (2023-01-07)
-------------------
- PR #467 - thanks to Slarag
- fix #465
- fix #464
0.16.4 (2022-08-04)
-------------------
- Regional fonts for RichText
@ -23,9 +29,6 @@
0.15.2 (2022-01-12)
-------------------
- fix #408
0.15.1 (2021-12-20)
-------------------
- Multi-rendering with same DocxTemplate object is now possible
see tests/multi_rendering.py
- fix #392

View File

@ -4,7 +4,7 @@ Created : 2015-03-12
@author: Eric Lapouyade
"""
__version__ = '0.16.4'
__version__ = '0.16.5'
# flake8: noqa
from .inline_image import InlineImage

View File

@ -43,8 +43,8 @@ class DocxTemplate(object):
self.is_rendered = False
self.is_saved = False
def init_docx(self):
if not self.docx or self.is_rendered:
def init_docx(self, reload: bool = True):
if not self.docx or (self.is_rendered and reload):
self.docx = Document(self.template_file)
self.is_rendered = False
@ -755,7 +755,7 @@ class DocxTemplate(object):
self.is_saved = True
def get_undeclared_template_variables(self, jinja_env: Optional[Environment] = None) -> Set[str]:
self.init_docx()
self.init_docx(reload=False)
xml = self.get_xml()
xml = self.patch_xml(xml)
for uri in [self.HEADER_URI, self.FOOTER_URI]:

15
tests/doc_properties.py Normal file
View File

@ -0,0 +1,15 @@
import os.path
import jinja2
from docxtpl import DocxTemplate, InlineImage
doctemplate = r'templates/doc_properties_tpl.docx'
tpl = DocxTemplate(doctemplate)
context = {
'test': 'HelloWorld'
}
tpl.render(context)
tpl.save("output/doc_properties.docx")

Binary file not shown.