From: Christian Heller Date: Wed, 17 Jul 2024 20:19:15 +0000 (+0200) Subject: Fix duplicate node IDs in Todo view. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/%7B%7B%20web_path%20%7D%7D/ledger?a=commitdiff_plain;h=b76436ee3192097556f1ce3d6415551cbc7fcaab;p=plomtask Fix duplicate node IDs in Todo view. --- diff --git a/plomtask/http.py b/plomtask/http.py index 2877068..ca4ce67 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -378,18 +378,19 @@ class TaskHandler(BaseHTTPRequestHandler): def walk_process_steps(node_id: int, process_step_nodes: list[ProcessStepsNode], - steps_nodes: list[TodoStepsNode]) -> None: + steps_nodes: list[TodoStepsNode]) -> int: for process_step_node in process_step_nodes: node_id += 1 node = TodoStepsNode(node_id, None, process_step_node.process, []) steps_nodes += [node] - walk_process_steps(node_id, - list(process_step_node.steps.values()), - node.children) + node_id = walk_process_steps( + node_id, list(process_step_node.steps.values()), + node.children) + return node_id def walk_todo_steps(node_id: int, todos: list[Todo], - steps_nodes: list[TodoStepsNode]) -> None: + steps_nodes: list[TodoStepsNode]) -> int: for todo in todos: matched = False for match in [item for item in steps_nodes @@ -399,15 +400,18 @@ class TaskHandler(BaseHTTPRequestHandler): matched = True for child in match.children: child.fillable = True - walk_todo_steps(node_id, todo.children, match.children) + node_id = walk_todo_steps( + node_id, todo.children, match.children) if not matched: node_id += 1 node = TodoStepsNode(node_id, todo, None, []) steps_nodes += [node] - walk_todo_steps(node_id, todo.children, node.children) + node_id = walk_todo_steps( + node_id, todo.children, node.children) + return node_id - def collect_adoptables_keys(steps_nodes: list[TodoStepsNode] - ) -> set[int]: + def collect_adoptables_keys( + steps_nodes: list[TodoStepsNode]) -> set[int]: ids = set() for node in steps_nodes: if not node.todo: @@ -420,12 +424,11 @@ class TaskHandler(BaseHTTPRequestHandler): todo_steps = [step.todo for step in todo.get_step_tree(set()).children] process_tree = todo.process.get_steps(self.conn, None) steps_todo_to_process: list[TodoStepsNode] = [] - walk_process_steps(0, list(process_tree.values()), - steps_todo_to_process) + last_node_id = walk_process_steps( + 0, list(process_tree.values()), steps_todo_to_process) for steps_node in steps_todo_to_process: steps_node.fillable = True - walk_todo_steps(len(steps_todo_to_process), todo_steps, - steps_todo_to_process) + walk_todo_steps(last_node_id, todo_steps, steps_todo_to_process) adoptables: dict[int, list[Todo]] = {} any_adoptables = [Todo.by_id(self.conn, t.id_) for t in Todo.by_date(self.conn, todo.date) @@ -434,7 +437,8 @@ class TaskHandler(BaseHTTPRequestHandler): for id_ in collect_adoptables_keys(steps_todo_to_process): adoptables[id_] = [t for t in any_adoptables if t.process.id_ == id_] - return {'todo': todo, 'steps_todo_to_process': steps_todo_to_process, + return {'todo': todo, + 'steps_todo_to_process': steps_todo_to_process, 'adoption_candidates_for': adoptables, 'process_candidates': Process.all(self.conn), 'todo_candidates': any_adoptables,