Simplify the code
This commit is contained in:
parent
2886a851e0
commit
2812487300
@ -357,16 +357,13 @@ class DocxTemplate(object):
|
|||||||
if jinja_env is None:
|
if jinja_env is None:
|
||||||
jinja_env = Environment()
|
jinja_env = Environment()
|
||||||
|
|
||||||
for k, v in self.docx.sections[0].part.related_parts.items():
|
for part in self.docx.sections[0].part.package.parts:
|
||||||
if v.content_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml':
|
if part.content_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml':
|
||||||
from lxml import etree as ET
|
tree = etree.fromstring(part.blob)
|
||||||
tree = ET.fromstring(v.blob)
|
|
||||||
for footnote in tree.findall('.//w:t', docx.oxml.ns.nsmap):
|
for footnote in tree.findall('.//w:t', docx.oxml.ns.nsmap):
|
||||||
if hasattr(footnote, 'text'):
|
if hasattr(footnote, 'text'):
|
||||||
footnote.text = jinja_env.from_string(footnote.text).render(context)
|
footnote.text = jinja_env.from_string(footnote.text).render(context)
|
||||||
for part in self.docx.sections[0].part.related_parts[k].package.parts:
|
part._blob = etree.tostring(tree)
|
||||||
if part.partname == v.partname:
|
|
||||||
part._blob = ET.tostring(tree, encoding='unicode').encode('utf8')
|
|
||||||
|
|
||||||
def resolve_listing(self, xml):
|
def resolve_listing(self, xml):
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user