home · contact · privacy
Slightly improve code readability with comment and renaming.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 18 Jul 2024 02:50:05 +0000 (04:50 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 18 Jul 2024 02:50:05 +0000 (04:50 +0200)
plomtask/http.py
plomtask/todos.py

index c7678a780dc0af7f6caa304dfb47b143b7346be9..3d8508cdb67655e0be86f709fd090ad21861021e 100644 (file)
@@ -16,7 +16,7 @@ from plomtask.exceptions import (HandledException, BadFormatException,
 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'
 
@@ -378,11 +378,11 @@ class TaskHandler(BaseHTTPRequestHandler):
 
         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()),
@@ -390,7 +390,7 @@ class TaskHandler(BaseHTTPRequestHandler):
             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
@@ -404,14 +404,14 @@ class TaskHandler(BaseHTTPRequestHandler):
                             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:
@@ -423,7 +423,7 @@ 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] = []
+        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:
index 4138abcd3051e3a7faf6a8165d04137b3c9cb01c..cb72640fb2c088ed317302df42cf5d12a4ff9108 100644 (file)
@@ -12,7 +12,7 @@ from plomtask.dating import valid_date
 
 
 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] = []
 
@@ -51,13 +51,13 @@ class TodoNode(DictableNode):
     _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']
 
@@ -120,7 +120,13 @@ class Todo(BaseModel[int], ConditionsRelations):
     @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)