From e60bbd142b5026748ee2181ca6758afef6202fb4 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Wed, 15 May 2024 08:51:00 +0200
Subject: [PATCH] Add Todo.comment display/posting in Todo view.

---
 plomtask/http.py    |  1 +
 templates/todo.html |  1 +
 tests/todos.py      | 12 ++++++------
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/plomtask/http.py b/plomtask/http.py
index 15f8376..2ecfcaa 100644
--- a/plomtask/http.py
+++ b/plomtask/http.py
@@ -248,6 +248,7 @@ class TaskHandler(BaseHTTPRequestHandler):
         todo.set_enables(self.conn, self.form_data.get_all_int('enables'))
         todo.set_disables(self.conn, self.form_data.get_all_int('disables'))
         todo.is_done = len(self.form_data.get_all_str('done')) > 0
+        todo.comment = self.form_data.get_str('comment')
         todo.save(self.conn)
         for condition in todo.enables:
             condition.save(self.conn)
diff --git a/templates/todo.html b/templates/todo.html
index 41a9eb1..f50b635 100644
--- a/templates/todo.html
+++ b/templates/todo.html
@@ -8,6 +8,7 @@ id: {{todo.id_}}<br />
 day: <a href="day?date={{todo.date}}">{{todo.date}}</a><br />
 process: <a href="process?id={{todo.process.id_}}">{{todo.process.title.newest|e}}</a><br />
 done: <input type="checkbox" name="done" {% if todo.is_done %}checked {% endif %} {% if not todo.is_doable %}disabled {% endif %}/><br /> 
+comment: <input name="comment" value="{{todo.comment|e}}"/>
 </p>
 <h4>conditions</h4>
 <table>
diff --git a/tests/todos.py b/tests/todos.py
index 419d3db..3158ecb 100644
--- a/tests/todos.py
+++ b/tests/todos.py
@@ -272,15 +272,15 @@ class TestsWithServer(TestCaseWithServer):
         self.check_post({}, '/todo?id=FOO', 400)
         self.check_post({}, '/todo?id=0', 404)
         # test posting naked entity
-        todo1 = post_and_reload({})
+        todo1 = post_and_reload({'comment': ''})
         self.assertEqual(todo1.children, [])
         self.assertEqual(todo1.parents, [])
         self.assertEqual(todo1.is_done, False)
         # test posting doneness
-        todo1 = post_and_reload({'done': ''})
+        todo1 = post_and_reload({'done': '', 'comment': ''})
         self.assertEqual(todo1.is_done, True)
         # test implicitly posting non-doneness
-        todo1 = post_and_reload({})
+        todo1 = post_and_reload({'comment': ''})
         self.assertEqual(todo1.is_done, False)
         # test malformed adoptions
         self.check_post({'adopt': 'foo'}, '/todo?id=1', 400)
@@ -290,17 +290,17 @@ class TestsWithServer(TestCaseWithServer):
         self.check_post({'day_comment': '', 'new_todo': 1},
                         '/day?date=2024-01-01', 302)
         # test todo 1 adopting todo 2
-        todo1 = post_and_reload({'adopt': 2})
+        todo1 = post_and_reload({'adopt': 2, 'comment': ''})
         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])
         # test todo1 cannot be set done with todo2 not done yet
-        todo1 = post_and_reload({'done': '', 'adopt': 2}, 400)
+        todo1 = post_and_reload({'done': '', 'adopt': 2, 'comment': ''}, 400)
         self.assertEqual(todo1.is_done, False)
         # test todo1 un-adopting todo 2 by just not sending an adopt
-        todo1 = post_and_reload({}, 302)
+        todo1 = post_and_reload({'comment': ''}, 302)
         todo2 = Todo.by_date(self.db_conn, '2024-01-01')[1]
         self.assertEqual(todo1.children, [])
         self.assertEqual(todo1.parents, [])
-- 
2.30.2