from plomtask.db import DatabaseConnection, BaseModel
from plomtask.misc import VersionedAttribute
from plomtask.conditions import Condition, ConditionsRelations
-from plomtask.exceptions import NotFoundException, BadFormatException
+from plomtask.exceptions import (NotFoundException, BadFormatException,
+ HandledException)
@dataclass
for step in self.explicit_steps:
step.save(db_conn)
+ def remove(self, db_conn: DatabaseConnection) -> None:
+ """Remove from DB, with dependencies."""
+ assert isinstance(self.id_, int)
+ for _ in db_conn.row_where('process_steps', 'step_process', self.id_):
+ raise HandledException('cannot remove Process in use')
+ for _ in db_conn.row_where('todos', 'process', self.id_):
+ raise HandledException('cannot remove Process in use')
+ db_conn.delete_where('process_conditions', 'process', self.id_)
+ db_conn.delete_where('process_enables', 'process', self.id_)
+ db_conn.delete_where('process_disables', 'process', self.id_)
+ for step in self.explicit_steps:
+ step.remove(db_conn)
+ db_conn.delete_where('process_titles', 'parent', self.id_)
+ db_conn.delete_where('process_descriptions', 'parent', self.id_)
+ db_conn.delete_where('process_efforts', 'parent', self.id_)
+ super().remove(db_conn)
+
class ProcessStep(BaseModel[int]):
"""Sub-unit of Processes."""
def save(self, db_conn: DatabaseConnection) -> None:
"""Default to simply calling self.save_core for simple cases."""
self.save_core(db_conn)
+
+ def remove(self, db_conn: DatabaseConnection) -> None:
+ """Remove from DB, and owner's .explicit_steps."""
+ owner = Process.by_id(db_conn, self.owner_id)
+ owner.explicit_steps.remove(self)
+ super().remove(db_conn)