From 2812487300baf7aa37cd5641420c04d4c5b94b05 Mon Sep 17 00:00:00 2001 From: Bart Broere Date: Tue, 17 Sep 2024 21:19:19 +0200 Subject: [PATCH] Simplify the code --- docxtpl/template.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/docxtpl/template.py b/docxtpl/template.py index 20bfb4d..29e1b08 100644 --- a/docxtpl/template.py +++ b/docxtpl/template.py @@ -357,16 +357,13 @@ class DocxTemplate(object): if jinja_env is None: jinja_env = Environment() - for k, v in self.docx.sections[0].part.related_parts.items(): - if v.content_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml': - from lxml import etree as ET - tree = ET.fromstring(v.blob) + for part in self.docx.sections[0].part.package.parts: + if part.content_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml': + tree = etree.fromstring(part.blob) for footnote in tree.findall('.//w:t', docx.oxml.ns.nsmap): if hasattr(footnote, 'text'): footnote.text = jinja_env.from_string(footnote.text).render(context) - for part in self.docx.sections[0].part.related_parts[k].package.parts: - if part.partname == v.partname: - part._blob = ET.tostring(tree, encoding='unicode').encode('utf8') + part._blob = etree.tostring(tree) def resolve_listing(self, xml):