self.is_done = is_done
self.day = day
self.children: list[Todo] = []
+ self.parents: list[Todo] = []
@classmethod
def from_table_row(cls, db_conn: DatabaseConnection, row: Row) -> Todo:
for row in db_conn.exec('SELECT child FROM todo_children '
'WHERE parent = ?', (id_,)):
todo.children += [cls.by_id(db_conn, row[0])]
+ for row in db_conn.exec('SELECT parent FROM todo_children '
+ 'WHERE child = ?', (id_,)):
+ todo.parents += [cls.by_id(db_conn, row[0])]
assert isinstance(todo, Todo)
return todo
raise BadFormatException('cannot adopt same child twice')
walk_steps(child)
self.children += [child]
+ child.parents += [self]
def save(self, db_conn: DatabaseConnection) -> None:
"""Write self and children to DB and its cache."""
self.check_post(form_data, '/todo?id=1', 302, '/')
todo1 = Todo.by_date(self.db_conn, '2024-01-01')[0]
self.assertEqual(todo1.children, [])
+ self.assertEqual(todo1.parents, [])
form_data = {'adopt': 'foo'}
self.check_post(form_data, '/todo?id=1', 400)
form_data = {'adopt': 1}
todo1 = Todo.by_date(self.db_conn, '2024-01-01')[0]
todo2 = Todo.by_date(self.db_conn, '2024-01-01')[1]
self.assertEqual(todo1.children, [todo2])
+ self.assertEqual(todo1.parents, [])
+ self.assertEqual(todo2.children, [])
+ self.assertEqual(todo2.parents, [todo1])
self.check_post(form_data, '/todo?id=1', 400, '/')
def test_do_GET_todo(self) -> None: