Run black on template.py
This commit is contained in:
parent
cbbeae57bd
commit
416729dddc
@ -887,34 +887,36 @@ class DocxTemplate(object):
|
|||||||
self.is_saved = True
|
self.is_saved = True
|
||||||
|
|
||||||
def get_undeclared_template_variables(
|
def get_undeclared_template_variables(
|
||||||
self, jinja_env: Optional[Environment] = None, context: Optional[Dict[str, Any]] = None
|
self,
|
||||||
|
jinja_env: Optional[Environment] = None,
|
||||||
|
context: Optional[Dict[str, Any]] = None,
|
||||||
) -> Set[str]:
|
) -> Set[str]:
|
||||||
# Create a temporary document to analyze the template without affecting the current state
|
# Create a temporary document to analyze the template without affecting the current state
|
||||||
temp_doc = Document(self.template_file)
|
temp_doc = Document(self.template_file)
|
||||||
|
|
||||||
# Get XML from the temporary document
|
# Get XML from the temporary document
|
||||||
xml = self.xml_to_string(temp_doc._element.body)
|
xml = self.xml_to_string(temp_doc._element.body)
|
||||||
xml = self.patch_xml(xml)
|
xml = self.patch_xml(xml)
|
||||||
|
|
||||||
# Add headers and footers
|
# Add headers and footers
|
||||||
for uri in [self.HEADER_URI, self.FOOTER_URI]:
|
for uri in [self.HEADER_URI, self.FOOTER_URI]:
|
||||||
for relKey, val in temp_doc._part.rels.items():
|
for relKey, val in temp_doc._part.rels.items():
|
||||||
if (val.reltype == uri) and (val.target_part.blob):
|
if (val.reltype == uri) and (val.target_part.blob):
|
||||||
_xml = self.xml_to_string(parse_xml(val.target_part.blob))
|
_xml = self.xml_to_string(parse_xml(val.target_part.blob))
|
||||||
xml += self.patch_xml(_xml)
|
xml += self.patch_xml(_xml)
|
||||||
|
|
||||||
if jinja_env:
|
if jinja_env:
|
||||||
env = jinja_env
|
env = jinja_env
|
||||||
else:
|
else:
|
||||||
env = Environment()
|
env = Environment()
|
||||||
|
|
||||||
parse_content = env.parse(xml)
|
parse_content = env.parse(xml)
|
||||||
all_variables = meta.find_undeclared_variables(parse_content)
|
all_variables = meta.find_undeclared_variables(parse_content)
|
||||||
|
|
||||||
# If context is provided, return only variables that are not in the context
|
# If context is provided, return only variables that are not in the context
|
||||||
if context is not None:
|
if context is not None:
|
||||||
provided_variables = set(context.keys())
|
provided_variables = set(context.keys())
|
||||||
return all_variables - provided_variables
|
return all_variables - provided_variables
|
||||||
|
|
||||||
# If no context provided, return all variables (original behavior)
|
# If no context provided, return all variables (original behavior)
|
||||||
return all_variables
|
return all_variables
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user