Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def include_docx_template(template_file, **kwargs):
"""Include the contents of one docx file inside another docx file."""
if this_thread.evaluation_context is None:
return 'ERROR: not in a docx file'
if template_file.__class__.__name__ in ('DAFile', 'DAFileList', 'DAFileCollection', 'DALocalFile'):
template_path = template_file.path()
else:
template_path = package_template_filename(template_file, package=this_thread.current_package)
sd = this_thread.misc['docx_template'].new_subdoc()
sd.subdocx = Document(template_path)
# We need to keep a copy of the subdocs so we can fix up the master template in the end (in parse.py)
# Given we're half way through processing the template, we can't fix the master template here
# we have to do it in post
if 'docx_subdocs' not in this_thread.misc:
this_thread.misc['docx_subdocs'] = []
this_thread.misc['docx_subdocs'].append(deepcopy(sd.subdocx))
# Fix the subdocs before they are included in the template
fix_subdoc(this_thread.misc['docx_template'], sd.subdocx)
first_paragraph = sd.subdocx.paragraphs[0]
for key, val in kwargs.items():
if hasattr(val, 'instanceName'):
the_repr = val.instanceName
else: