X-Git-Url: https://plomlompom.com/repos/feed.xml?a=blobdiff_plain;f=plomtask%2Ftodos.py;h=348dbddcbb96338ba1f1e10da50e094e36b92f63;hb=89624d5e05480c832a079008bbb9992f411be0dd;hp=840c2985b846de2241def493be68b58939f34657;hpb=33cff8c5f6427c4e7e617c459ee024b5b6c2d32e;p=plomtask diff --git a/plomtask/todos.py b/plomtask/todos.py index 840c298..348dbdd 100644 --- a/plomtask/todos.py +++ b/plomtask/todos.py @@ -181,29 +181,11 @@ class Todo(BaseModel): self.save_core(db_conn) assert isinstance(self.id_, int) db_conn.cached_todos[self.id_] = self - db_conn.exec('DELETE FROM todo_children WHERE parent = ?', - (self.id_,)) - for child in self.children: - db_conn.exec('INSERT INTO todo_children VALUES (?, ?)', - (self.id_, child.id_)) - db_conn.exec('DELETE FROM todo_fulfills WHERE todo = ?', (self.id_,)) - for condition in self.fulfills: - if condition.id_ is None: - raise NotFoundException('Fulfilled Condition of Todo ' - 'without ID (not saved?)') - db_conn.exec('INSERT INTO todo_fulfills VALUES (?, ?)', - (self.id_, condition.id_)) - db_conn.exec('DELETE FROM todo_undoes WHERE todo = ?', (self.id_,)) - for condition in self.undoes: - if condition.id_ is None: - raise NotFoundException('Undone Condition of Todo ' - 'without ID (not saved?)') - db_conn.exec('INSERT INTO todo_undoes VALUES (?, ?)', - (self.id_, condition.id_)) - db_conn.exec('DELETE FROM todo_conditions WHERE todo = ?', (self.id_,)) - for condition in self.conditions: - if condition.id_ is None: - raise NotFoundException('Condition of Todo ' - 'without ID (not saved?)') - db_conn.exec('INSERT INTO todo_conditions VALUES (?, ?)', - (self.id_, condition.id_)) + db_conn.rewrite_relations('todo_children', 'parent', self.id_, + [[c.id_] for c in self.children]) + db_conn.rewrite_relations('todo_conditions', 'todo', self.id_, + [[c.id_] for c in self.conditions]) + db_conn.rewrite_relations('todo_fulfills', 'todo', self.id_, + [[c.id_] for c in self.fulfills]) + db_conn.rewrite_relations('todo_undoes', 'todo', self.id_, + [[c.id_] for c in self.undoes])