Commit 067f3c4e authored by Matthieu Boileau's avatar Matthieu Boileau

Fix bug in tree generation

parent 605130ae
......@@ -475,19 +475,20 @@ class Website:
def insert_node(node_id):
"""A recursive function to insert a node in the anytree.Node tree"""
node_name = get_label(node_id)
if node_id == 0:
self.rubrique_tree[node_name] = anytree.Node(node_name)
else:
parent_id = self.parents[node_id]
parent_name = get_label(parent_id)
parent = self.rubrique_tree.get(parent_name)
if not parent:
# insert parent if it does not exist
insert_node(parent_id)
self.rubrique_tree[node_name] = anytree.Node(node_name, parent=parent)
if node_name not in self.rubrique_tree:
# Create node only if it does not exist
if node_id == 0:
# This the root node
self.rubrique_tree[node_name] = anytree.Node(node_name)
else:
parent_id = self.parents[node_id]
parent_name = get_label(parent_id)
parent = self.rubrique_tree.get(parent_name)
if not parent:
# insert parent if it does not exist
insert_node(parent_id)
parent = self.rubrique_tree.get(parent_name)
self.rubrique_tree[node_name] = anytree.Node(node_name, parent=parent)
self.labels[0] = "root" # Root node label
......@@ -501,12 +502,10 @@ class Website:
#rubrique_node = anytree.search.find_by_attr(self.rubrique_root, article.rubrique, name="id")
#rubrique_node.count += 1
# Render the AnyNode object like the bash "tree" command would do
for pre, fill, rubrique_node in anytree.RenderTree(self.rubrique_tree['0: root']):
print(f"{pre}{rubrique_node.name}")
def _build_doc_index(self):
"""Build the index dictionary: {id_doc: file_path}"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment