self.description.save(db_conn)
assert isinstance(self.id_, int)
db_conn.cached_conditions[self.id_] = self
+
+
+class ConditionsRelations:
+ """Methods for handling relations to Conditions, for Todo and Process."""
+
+ def set_conditions(self, db_conn: DatabaseConnection, ids: list[int],
+ target: str = 'conditions') -> None:
+ """Set self.[target] to Conditions identified by ids."""
+ target_list = getattr(self, target)
+ while len(target_list) > 0:
+ target_list.pop()
+ for id_ in ids:
+ target_list += [Condition.by_id(db_conn, id_)]
+
+ def set_enables(self, db_conn: DatabaseConnection,
+ ids: list[int]) -> None:
+ """Set self.enables to Conditions identified by ids."""
+ self.set_conditions(db_conn, ids, 'enables')
+
+ def set_disables(self, db_conn: DatabaseConnection,
+ ids: list[int]) -> None:
+ """Set self.disables to Conditions identified by ids."""
+ self.set_conditions(db_conn, ids, 'disables')
from typing import Any, Set
from plomtask.db import DatabaseConnection, BaseModel
from plomtask.misc import VersionedAttribute
-from plomtask.conditions import Condition
+from plomtask.conditions import Condition, ConditionsRelations
from plomtask.exceptions import NotFoundException, BadFormatException
-class Process(BaseModel):
+class Process(BaseModel, ConditionsRelations):
"""Template for, and metadata for, Todos, and their arrangements."""
table_name = 'processes'
walk_steps(step_id, step_node)
return steps
- def set_conditions(self, db_conn: DatabaseConnection, ids: list[int],
- trgt: str = 'conditions') -> None:
- """Set self.[target] to Conditions identified by ids."""
- trgt_list = getattr(self, trgt)
- while len(trgt_list) > 0:
- trgt_list.pop()
- for id_ in ids:
- trgt_list += [Condition.by_id(db_conn, id_)]
-
- def set_enables(self, db_conn: DatabaseConnection,
- ids: list[int]) -> None:
- """Set self.enables to Conditions identified by ids."""
- self.set_conditions(db_conn, ids, 'enables')
-
- def set_disables(self, db_conn: DatabaseConnection,
- ids: list[int]) -> None:
- """Set self.disables to Conditions identified by ids."""
- self.set_conditions(db_conn, ids, 'disables')
-
def _add_step(self,
db_conn: DatabaseConnection,
id_: int | None,
from sqlite3 import Row
from plomtask.db import DatabaseConnection, BaseModel
from plomtask.processes import Process
-from plomtask.conditions import Condition
+from plomtask.conditions import Condition, ConditionsRelations
from plomtask.exceptions import (NotFoundException, BadFormatException,
HandledException)
-class Todo(BaseModel):
+class Todo(BaseModel, ConditionsRelations):
"""Individual actionable."""
# pylint: disable=too-many-instance-attributes
for condition in self.disables:
condition.is_active = False
- def set_disables(self, db_conn: DatabaseConnection,
- ids: list[int]) -> None:
- """Set self.disables to Conditions identified by ids."""
- self.set_conditions(db_conn, ids, 'disables')
-
- def set_enables(self, db_conn: DatabaseConnection,
- ids: list[int]) -> None:
- """Set self.enables to Conditions identified by ids."""
- self.set_conditions(db_conn, ids, 'enables')
-
- def set_conditions(self, db_conn: DatabaseConnection, ids: list[int],
- target: str = 'conditions') -> None:
- """Set self.[target] to Conditions identified by ids."""
- target_list = getattr(self, target)
- while len(target_list) > 0:
- target_list.pop()
- for id_ in ids:
- target_list += [Condition.by_id(db_conn, id_)]
-
def add_child(self, child: Todo) -> None:
"""Add child to self.children, guard against recursion"""
def walk_steps(node: Todo) -> None: