Skip to content

Commit 2812487

Browse files
authored
Simplify the code
1 parent 2886a85 commit 2812487

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

docxtpl/template.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,16 +357,13 @@ def render_footnotes(
357357
if jinja_env is None:
358358
jinja_env = Environment()
359359

360-
for k, v in self.docx.sections[0].part.related_parts.items():
361-
if v.content_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml':
362-
from lxml import etree as ET
363-
tree = ET.fromstring(v.blob)
360+
for part in self.docx.sections[0].part.package.parts:
361+
if part.content_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml':
362+
tree = etree.fromstring(part.blob)
364363
for footnote in tree.findall('.//w:t', docx.oxml.ns.nsmap):
365364
if hasattr(footnote, 'text'):
366365
footnote.text = jinja_env.from_string(footnote.text).render(context)
367-
for part in self.docx.sections[0].part.related_parts[k].package.parts:
368-
if part.partname == v.partname:
369-
part._blob = ET.tostring(tree, encoding='unicode').encode('utf8')
366+
part._blob = etree.tostring(tree)
370367

371368
def resolve_listing(self, xml):
372369

0 commit comments

Comments
 (0)