Added possibility to skip missing pictures instead of raising ValueError exception.
This commit is contained in:
parent
b97fa32f10
commit
97df786298
@ -46,6 +46,7 @@ class DocxTemplate(object):
|
|||||||
self.docx = None
|
self.docx = None
|
||||||
self.is_rendered = False
|
self.is_rendered = False
|
||||||
self.is_saved = False
|
self.is_saved = False
|
||||||
|
self.allow_missing_pics = False
|
||||||
|
|
||||||
def init_docx(self, reload: bool = True):
|
def init_docx(self, reload: bool = True):
|
||||||
if not self.docx or (self.is_rendered and reload):
|
if not self.docx or (self.is_rendered and reload):
|
||||||
@ -797,6 +798,7 @@ class DocxTemplate(object):
|
|||||||
if rel.reltype in (REL_TYPE.HEADER, REL_TYPE.FOOTER):
|
if rel.reltype in (REL_TYPE.HEADER, REL_TYPE.FOOTER):
|
||||||
self._replace_docx_part_pics(rel.target_part, replaced_pics)
|
self._replace_docx_part_pics(rel.target_part, replaced_pics)
|
||||||
|
|
||||||
|
if not self.allow_missing_pics:
|
||||||
# make sure all template images defined by user were replaced
|
# make sure all template images defined by user were replaced
|
||||||
for img_id, replaced in replaced_pics.items():
|
for img_id, replaced in replaced_pics.items():
|
||||||
if not replaced:
|
if not replaced:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user