from plomtask.db import DatabaseConnection, DatabaseFile, BaseModel
from plomtask.processes import Process, ProcessStep, ProcessStepsNode
from plomtask.conditions import Condition
-from plomtask.todos import Todo, TodoStepsNode, DictableNode
+from plomtask.todos import Todo, TodoOrProcStepNode, DictableNode
TEMPLATES_DIR = 'templates'
def walk_process_steps(node_id: int,
process_step_nodes: list[ProcessStepsNode],
- steps_nodes: list[TodoStepsNode]) -> int:
+ steps_nodes: list[TodoOrProcStepNode]) -> int:
for process_step_node in process_step_nodes:
node_id += 1
- node = TodoStepsNode(node_id, None, process_step_node.process,
- [])
+ node = TodoOrProcStepNode(node_id, None,
+ process_step_node.process, [])
steps_nodes += [node]
node_id = walk_process_steps(
node_id, list(process_step_node.steps.values()),
return node_id
def walk_todo_steps(node_id: int, todos: list[Todo],
- steps_nodes: list[TodoStepsNode]) -> int:
+ steps_nodes: list[TodoOrProcStepNode]) -> int:
for todo in todos:
matched = False
for match in [item for item in steps_nodes
node_id, todo.children, match.children)
if not matched:
node_id += 1
- node = TodoStepsNode(node_id, todo, None, [])
+ node = TodoOrProcStepNode(node_id, todo, None, [])
steps_nodes += [node]
node_id = walk_todo_steps(
node_id, todo.children, node.children)
return node_id
def collect_adoptables_keys(
- steps_nodes: list[TodoStepsNode]) -> set[int]:
+ steps_nodes: list[TodoOrProcStepNode]) -> set[int]:
ids = set()
for node in steps_nodes:
if not node.todo:
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] = []
+ steps_todo_to_process: list[TodoOrProcStepNode] = []
last_node_id = walk_process_steps(
0, list(process_tree.values()), steps_todo_to_process)
for steps_node in steps_todo_to_process:
class DictableNode:
- """Template for TodoNode, TodoStepsNode providing .as_dict_and_refs."""
+ """Template for TodoNode, TodoOrStepsNode providing .as_dict_and_refs."""
# pylint: disable=too-few-public-methods
_to_dict: list[str] = []
_to_dict = ['todo', 'seen', 'children']
-class TodoStepsNode(DictableNode):
- """Collect what's useful for Todo steps tree display."""
+class TodoOrProcStepNode(DictableNode):
+ """Collect what's useful for Todo-or-ProcessStep tree display."""
# pylint: disable=too-few-public-methods
node_id: int
todo: Todo | None
process: Process | None
- children: list[TodoStepsNode] # pylint: disable=undefined-variable
+ children: list[TodoOrProcStepNode] # pylint: disable=undefined-variable
fillable: bool = False
_to_dict = ['node_id', 'todo', 'process', 'children', 'fillable']
@classmethod
def create_with_children(cls, db_conn: DatabaseConnection,
process_id: int, date: str) -> Todo:
- """Create Todo of process for date, ensure children."""
+ """Create Todo of process for date, ensure children demanded by chain.
+
+ At minimum creates Todo of process_id, but checks the respective
+ Process for its step tree, and walks down that to provide the initial
+ Todo with all descendants defined there, either adopting existing
+ Todos, or creating them where necessary.
+ """
def key_order_func(n: ProcessStepsNode) -> int:
assert isinstance(n.process.id_, int)