home · contact · privacy
Enable toggling of Todo.is_done.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 13 Apr 2024 01:40:17 +0000 (03:40 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 13 Apr 2024 01:40:17 +0000 (03:40 +0200)
plomtask/http.py
plomtask/todos.py
templates/day.html
tests/todos.py

index e65164ac0e24fa196435830bed014b1f0d654cc1..5d165ecf90f1ca6ebaed77e55b73a5d55ff428b8 100644 (file)
@@ -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,
index e8e00acbd8cd77d58d7d99ce2d0551288ffb96f4..2b9fd1d8edb2fa159f3955f469a6b3d394aa1efa 100644 (file)
@@ -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
index 0953d52446555fb695f021121ac3c9798827597d..637e08d94ad2e72da8fbcbd009b0c428131edaee 100644 (file)
@@ -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 %}
index a377920d615fec4d78f44ac33ec0856d6d8f2989..6ef8b091396b9d1047a1122ce8a446a7c995c14d 100644 (file)
@@ -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}