elapouya / python-docx-template

Use a docx as a jinja2 template
GNU Lesser General Public License v2.1
1.91k stars 378 forks source link

Fix #465 #466

Closed Slarag closed 1 year ago

elapouya commented 1 year ago

This is not a good PR : the goal of the test you modified was to force reload of template to avoid conflict with previous rendering.

Slarag commented 1 year ago

Would it be an option to add an optional boolean parameter "reload" to init_docx() to fix the behavior of get_undeclared_template_variables()?

    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
    ...
    def get_undeclared_template_variables(self, jinja_env: Optional[Environment] = None) -> Set[str]:
        self.init_docx(reload=False)
        ...
elapouya commented 1 year ago

Good idea, I will code that.