home
·
contact
·
privacy
projects
/
plomtask
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Enhance BaseModel comparisons by hashing versioned and relations attributes.
[plomtask]
/
plomtask
/
conditions.py
diff --git
a/plomtask/conditions.py
b/plomtask/conditions.py
index 45aa62b9b27a026c75549aea3350640c419d8a5e..d2559272cd876c5b071b59437998e3356409cd07 100644
(file)
--- a/
plomtask/conditions.py
+++ b/
plomtask/conditions.py
@@
-3,7
+3,7
@@
from __future__ import annotations
from typing import Any
from sqlite3 import Row
from plomtask.db import DatabaseConnection, BaseModel
from typing import Any
from sqlite3 import Row
from plomtask.db import DatabaseConnection, BaseModel
-from plomtask.
misc
import VersionedAttribute
+from plomtask.
versioned_attributes
import VersionedAttribute
from plomtask.exceptions import HandledException
from plomtask.exceptions import HandledException
@@
-11,6
+11,8
@@
class Condition(BaseModel[int]):
"""Non-Process dependency for ProcessSteps and Todos."""
table_name = 'conditions'
to_save = ['is_active']
"""Non-Process dependency for ProcessSteps and Todos."""
table_name = 'conditions'
to_save = ['is_active']
+ to_save_versioned = ['title', 'description']
+ to_search = ['title.newest', 'description.newest']
def __init__(self, id_: int | None, is_active: bool = False) -> None:
super().__init__(id_)
def __init__(self, id_: int | None, is_active: bool = False) -> None:
super().__init__(id_)
@@
-30,28
+32,31
@@
class Condition(BaseModel[int]):
getattr(condition, name).history_from_row(row_)
return condition
getattr(condition, name).history_from_row(row_)
return condition
- def save(self, db_conn: DatabaseConnection) -> None:
- """Save self and its VersionedAttributes to DB and cache."""
- self.save_core(db_conn)
- self.title.save(db_conn)
- self.description.save(db_conn)
-
def remove(self, db_conn: DatabaseConnection) -> None:
def remove(self, db_conn: DatabaseConnection) -> None:
- """Remove from DB, with dependencies."""
- assert isinstance(self.id_, int)
+ """Remove from DB, with VersionedAttributes.
+
+ Checks for Todos and Processes that depend on Condition, prohibits
+ deletion if found.
+ """
+ if self.id_ is None:
+ raise HandledException('cannot remove unsaved item')
for item in ('process', 'todo'):
for item in ('process', 'todo'):
- for attr in ('conditions', 'enables', 'disables'):
+ for attr in ('conditions', '
blockers', '
enables', 'disables'):
table_name = f'{item}_{attr}'
for _ in db_conn.row_where(table_name, 'condition', self.id_):
raise HandledException('cannot remove Condition in use')
table_name = f'{item}_{attr}'
for _ in db_conn.row_where(table_name, 'condition', self.id_):
raise HandledException('cannot remove Condition in use')
- db_conn.delete_where('condition_titles', 'parent', self.id_)
- db_conn.delete_where('condition_descriptions', 'parent', self.id_)
super().remove(db_conn)
class ConditionsRelations:
"""Methods for handling relations to Conditions, for Todo and Process."""
super().remove(db_conn)
class ConditionsRelations:
"""Methods for handling relations to Conditions, for Todo and Process."""
+ def __init__(self) -> None:
+ self.conditions: list[Condition] = []
+ self.blockers: list[Condition] = []
+ self.enables: list[Condition] = []
+ self.disables: list[Condition] = []
+
def set_conditions(self, db_conn: DatabaseConnection, ids: list[int],
target: str = 'conditions') -> None:
"""Set self.[target] to Conditions identified by ids."""
def set_conditions(self, db_conn: DatabaseConnection, ids: list[int],
target: str = 'conditions') -> None:
"""Set self.[target] to Conditions identified by ids."""
@@
-61,6
+66,11
@@
class ConditionsRelations:
for id_ in ids:
target_list += [Condition.by_id(db_conn, id_)]
for id_ in ids:
target_list += [Condition.by_id(db_conn, id_)]
+ def set_blockers(self, db_conn: DatabaseConnection,
+ ids: list[int]) -> None:
+ """Set self.enables to Conditions identified by ids."""
+ self.set_conditions(db_conn, ids, 'blockers')
+
def set_enables(self, db_conn: DatabaseConnection,
ids: list[int]) -> None:
"""Set self.enables to Conditions identified by ids."""
def set_enables(self, db_conn: DatabaseConnection,
ids: list[int]) -> None:
"""Set self.enables to Conditions identified by ids."""