From: Christian Heller <c.heller@plomlompom.de>
Date: Sat, 13 Apr 2024 01:40:17 +0000 (+0200)
Subject: Enable toggling of Todo.is_done.
X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/%7B%7Bprefix%7D%7D/day_todos?a=commitdiff_plain;h=12195a1fe2c15334c866036eaa171eb8e92f0408;p=plomtask

Enable toggling of Todo.is_done.
---

diff --git a/plomtask/http.py b/plomtask/http.py
index e65164a..5d165ec 100644
--- a/plomtask/http.py
+++ b/plomtask/http.py
@@ -209,6 +209,7 @@ class TaskHandler(BaseHTTPRequestHandler):
         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,
diff --git a/plomtask/todos.py b/plomtask/todos.py
index e8e00ac..2b9fd1d 100644
--- a/plomtask/todos.py
+++ b/plomtask/todos.py
@@ -25,7 +25,7 @@ class Todo:
         """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
diff --git a/templates/day.html b/templates/day.html
index 0953d52..637e08d 100644
--- a/templates/day.html
+++ b/templates/day.html
@@ -1,7 +1,7 @@
 {% 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 %}
diff --git a/tests/todos.py b/tests/todos.py
index a377920..6ef8b09 100644
--- a/tests/todos.py
+++ b/tests/todos.py
@@ -119,6 +119,12 @@ class TestsWithServer(TestCaseWithServer):
         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}