Simplify the code

This commit is contained in:
Bart Broere 2024-09-17 21:19:19 +02:00 committed by GitHub
parent 2886a851e0
commit 2812487300
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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):