if child_id is not None:
child = Todo.by_id(conn, child_id)
todo.add_child(child)
+ todo.is_done = len(form_data.get_all_str('done')) > 0
todo.save(conn)
def do_POST_process(self, conn: DatabaseConnection, params: ParamsParser,
"""Make Todo from database row, write to DB cache."""
todo = cls(id_=row[0],
process=Process.by_id(db_conn, row[1]),
- is_done=row[2],
+ is_done=bool(row[2]),
day=Day.by_date(db_conn, row[3]))
assert todo.id_ is not None
db_conn.cached_todos[todo.id_] = todo
{% extends 'base.html' %}
{% macro todo_with_children(todo, indent) %}
-<li>{% for i in range(indent) %}+{% endfor %}<a href="todo?id={{todo.id_}}">{{todo.process.title.newest|e}}</a>
+<li>{% for i in range(indent) %}+{% endfor %} [{% if todo.is_done %}x{% else %} {% endif %}] <a href="todo?id={{todo.id_}}">{{todo.process.title.newest|e}}</a>
{% for child in todo.children %}
{{ todo_with_children(child, indent+1) }}
{% endfor %}
todo1 = Todo.by_date(self.db_conn, '2024-01-01')[0]
self.assertEqual(todo1.children, [])
self.assertEqual(todo1.parents, [])
+ self.assertEqual(todo1.is_done, False)
+ form_data = {'done': ''}
+ self.check_post(form_data, '/todo?id=1', 302, '/')
+ self.db_conn.cached_todos = {}
+ todo1 = Todo.by_date(self.db_conn, '2024-01-01')[0]
+ self.assertEqual(todo1.is_done, True)
form_data = {'adopt': 'foo'}
self.check_post(form_data, '/todo?id=1', 400)
form_data = {'adopt': 1}