From: Christian Heller Date: Mon, 22 Apr 2024 03:56:14 +0000 (+0200) Subject: On posting a new Todo to a Day, auto-adopt existing ones per its Process' .explicit_s... X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7Bdb.prefix%7D%7D/%7B%7Btodo.date%7D%7D?a=commitdiff_plain;h=a7adce16f1969400cb988ff900f504157e454cce;p=plomtask On posting a new Todo to a Day, auto-adopt existing ones per its Process' .explicit_steps. --- diff --git a/plomtask/http.py b/plomtask/http.py index 140f6bc..64cc6f9 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -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.""" diff --git a/tests/todos.py b/tests/todos.py index 6e88425..b5953dc 100644 --- a/tests/todos.py +++ b/tests/todos.py @@ -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}