home · contact · privacy
On posting a new Todo to a Day, auto-adopt existing ones per its Process' .explicit_s...
authorChristian Heller <c.heller@plomlompom.de>
Mon, 22 Apr 2024 03:56:14 +0000 (05:56 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 22 Apr 2024 03:56:14 +0000 (05:56 +0200)
plomtask/http.py
tests/todos.py

index 140f6bcfb16dbe89222b324d7e06bd7545f2f0f3..64cc6f95871174c71badbf495f9f3dfe56f74cc1 100644 (file)
@@ -195,10 +195,17 @@ class TaskHandler(BaseHTTPRequestHandler):
         day = Day.by_id(self.conn, date, create=True)
         day.comment = self.form_data.get_str('comment')
         day.save(self.conn)
+        existing_todos = Todo.by_date(self.conn, date)
         for process_id in self.form_data.get_all_int('new_todo'):
             process = Process.by_id(self.conn, process_id)
             todo = Todo(None, process, False, day.date)
             todo.save(self.conn)
+            for step in todo.process.explicit_steps:
+                for t in [t for t in existing_todos
+                          if t.process.id_ == step.step_process_id]:
+                    todo.add_child(t)
+                    break
+            todo.save(self.conn)
 
     def do_POST_todo(self) -> None:
         """Update Todo and its children."""
index 6e8842570baa4a2f1eab2293c3ab664efca2ac72..b5953dc69c0d593113095ddd3e82c463e03ec253 100644 (file)
@@ -312,6 +312,23 @@ class TestsWithServer(TestCaseWithServer):
         self.assertEqual(todo2.children, [])
         self.assertEqual(todo2.parents, [])
 
+    def test_do_POST_day_todo_adoption(self) -> None:
+        """Test Todos posted to Day view may adopt existing Todos."""
+        form_data = {'title': '', 'description': '', 'effort': 1}
+        self.check_post(form_data, '/process', 302, '/')
+        form_data['new_top_step'] = 1
+        self.check_post(form_data, '/process', 302, '/')
+        form_data = {'comment': '', 'new_todo': 1}
+        self.check_post(form_data, '/day?date=2024-01-01', 302)
+        form_data = {'comment': '', 'new_todo': 2}
+        self.check_post(form_data, '/day?date=2024-01-01', 302)
+        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, [])
+        self.assertEqual(todo1.parents, [todo2])
+        self.assertEqual(todo2.children, [todo1])
+        self.assertEqual(todo2.parents, [])
+
     def test_do_GET_todo(self) -> None:
         """Test GET /todo response codes."""
         form_data = {'title': '', 'description': '', 'effort': 1}