home · contact · privacy
Create choice for creating Todos with or without children.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 12 Jun 2024 01:53:10 +0000 (03:53 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 12 Jun 2024 01:53:10 +0000 (03:53 +0200)
plomtask/http.py
templates/day.html
templates/todo.html
tests/days.py
tests/todos.py

index 0aa692545d3e5ae38f4be7190a697df40259dcb0..e9e23633a92ddd5b02d9402dfaefae357476b125 100644 (file)
@@ -155,6 +155,7 @@ class TaskHandler(BaseHTTPRequestHandler):
     def do_GET_day(self) -> dict[str, object]:
         """Show single Day of ?date=."""
         date = self.params.get_str('date', date_in_n_days(0))
+        make_type = self.params.get_str('make_type')
         todays_todos = Todo.by_date(self.conn, date)
         total_effort = 0.0
         for todo in todays_todos:
@@ -178,6 +179,7 @@ class TaskHandler(BaseHTTPRequestHandler):
         return {'day': Day.by_id(self.conn, date, create=True),
                 'total_effort': total_effort,
                 'top_nodes': top_nodes,
+                'make_type': make_type,
                 'enablers_for': enablers_for,
                 'disablers_for': disablers_for,
                 'conditions_present': conditions_present,
@@ -411,8 +413,14 @@ class TaskHandler(BaseHTTPRequestHandler):
         day = Day.by_id(self.conn, date, create=True)
         day.comment = self.form_data.get_str('day_comment')
         day.save(self.conn)
+        make_type = self.form_data.get_str('make_type')
         for process_id in sorted(self.form_data.get_all_int('new_todo')):
-            Todo.create_with_children(self.conn, process_id, date)
+            if 'empty' == make_type:
+                process = Process.by_id(self.conn, process_id)
+                todo = Todo(None, process, False, date)
+                todo.save(self.conn)
+            else:
+                Todo.create_with_children(self.conn, process_id, date)
         done_ids = self.form_data.get_all_int('done')
         comments = self.form_data.get_all_str('comment')
         efforts = self.form_data.get_all_str('effort')
@@ -428,10 +436,12 @@ class TaskHandler(BaseHTTPRequestHandler):
                 condition.save(self.conn)
             for condition in todo.disables:
                 condition.save(self.conn)
-        return f'/day?date={date}'
+        return f'/day?date={date}&make_type={make_type}'
 
     def do_POST_todo(self) -> str:
         """Update Todo and its children."""
+        # pylint: disable=too-many-locals
+        # pylint: disable=too-many-branches
         id_ = self.params.get_int('id')
         for _ in self.form_data.get_all_str('delete'):
             todo = Todo .by_id(self.conn, id_)
@@ -439,11 +449,14 @@ class TaskHandler(BaseHTTPRequestHandler):
             return '/'
         todo = Todo.by_id(self.conn, id_)
         adopted_child_ids = self.form_data.get_all_int('adopt')
-        processes_to_make = self.form_data.get_all_int('make')
+        processes_to_make_full = self.form_data.get_all_int('make_full')
+        processes_to_make_empty = self.form_data.get_all_int('make_empty')
         fill_fors = self.form_data.get_first_strings_starting('fill_for_')
         for v in fill_fors.values():
-            if v.startswith('make_'):
-                processes_to_make += [int(v[5:])]
+            if v.startswith('make_empty_'):
+                processes_to_make_empty += [int(v[11:])]
+            elif v.startswith('make_full_'):
+                processes_to_make_full += [int(v[10:])]
             elif v != 'ignore':
                 adopted_child_ids += [int(v)]
         to_remove = []
@@ -459,7 +472,12 @@ class TaskHandler(BaseHTTPRequestHandler):
                 continue
             child = Todo.by_id(self.conn, child_id)
             todo.add_child(child)
-        for process_id in processes_to_make:
+        for process_id in processes_to_make_empty:
+            process = Process.by_id(self.conn, process_id)
+            made = Todo(None, process, False, todo.date)
+            made.save(self.conn)
+            todo.add_child(made)
+        for process_id in processes_to_make_full:
             made = Todo.create_with_children(self.conn, process_id, todo.date)
             todo.add_child(made)
         effort = self.form_data.get_str('effort', ignore_strict=True)
index 2941105747db5a7e0ca5b2f26e2c1234b9d0a2c2..a34f05b3ad5a6c84135ad518fe83a44530815333 100644 (file)
@@ -141,6 +141,12 @@ comment:
 <p>
 add: <input type="text" name="new_todo" list="processes">
 </p>
+<p>
+<select name="make_type">
+<option value="full">make new todos with children</option>
+<option value="empty"{% if make_type == "empty" %}selected {% endif %}>make new todos without children</option>
+</select>
+</p>
 
 <table>
 
index 5ffa354e172a83aec7bd016cff07a4917c954200..c2fb01d710d8d9d0081d70e124f3a38d241ec7e3 100644 (file)
@@ -25,7 +25,8 @@ select{ font-size: 0.5em; margin: 0; padding: 0; }
 {% if indent == 0 %}
 · fill: <select name="fill_for_{{item.id_}}">
 <option value="ignore">--</option>
-<option value="make_{{item.process.id_}}">make</option>
+<option value="make_empty_{{item.process.id_}}">make empty</option>
+<option value="make_full_{{item.process.id_}}">make full</option>
 {% for adoptable in adoption_candidates_for[item.process.id_] %}
 <option value="{{adoptable.id_}}">adopt #{{adoptable.id_}}{% if adoptable.comment %} / {{adoptable.comment}}{% endif %}</option>
 {% endfor %}
@@ -107,7 +108,8 @@ select{ font-size: 0.5em; margin: 0; padding: 0; }
 </table>
 {% endif %}
 adopt: <input type="text" name="adopt" list="todo_candidates" autocomplete="off" /><br />
-make: <input type="text" name="make" list="process_candidates" autocomplete="off" />
+make empty: <input type="text" name="make_empty" list="process_candidates" autocomplete="off" /><br />
+make full: <input type="text" name="make_full" list="process_candidates" autocomplete="off" />
 </td>
 </tr>
 </table>
index d34d7ba794e16476fd2f0c54fa28f39c5e77ea74..286f75815ef51e74ade9e15e96bdb85dc4218a4b 100644 (file)
@@ -118,8 +118,8 @@ class TestsWithServer(TestCaseWithServer):
 
     def test_do_POST_day(self) -> None:
         """Test POST /day."""
-        form_data = {'day_comment': ''}
+        form_data = {'day_comment': '', 'make_type': 'full'}
         self.check_post(form_data, '/day', 400)
         self.check_post(form_data, '/day?date=foo', 400)
-        self.check_post(form_data, '/day?date=2024-01-01', 302)
+        self.check_post(form_data, '/day?date=2024-01-01&make_type=full', 302)
         self.check_post({'foo': ''}, '/day?date=2024-01-01', 400)
index b28ebd8cdda37c973cf468daa2683140f855dd39..1a9eab61c0f77932c11b24ebae15cfc9a982287b 100644 (file)
@@ -243,11 +243,11 @@ class TestsWithServer(TestCaseWithServer):
         self.post_process(2)
         proc = Process.by_id(self.db_conn, 1)
         proc2 = Process.by_id(self.db_conn, 2)
-        form_data = {'day_comment': ''}
-        self.check_post(form_data, '/day?date=2024-01-01', 302)
+        form_data = {'day_comment': '', 'make_type': 'full'}
+        self.check_post(form_data, '/day?date=2024-01-01&make_type=full', 302)
         self.assertEqual(Todo.by_date(self.db_conn, '2024-01-01'), [])
         form_data['new_todo'] = str(proc.id_)
-        self.check_post(form_data, '/day?date=2024-01-01', 302)
+        self.check_post(form_data, '/day?date=2024-01-01&make_type=full', 302)
         todos = Todo.by_date(self.db_conn, '2024-01-01')
         self.assertEqual(1, len(todos))
         todo1 = todos[0]
@@ -255,7 +255,7 @@ class TestsWithServer(TestCaseWithServer):
         self.assertEqual(todo1.process.id_, proc.id_)
         self.assertEqual(todo1.is_done, False)
         form_data['new_todo'] = str(proc2.id_)
-        self.check_post(form_data, '/day?date=2024-01-01', 302)
+        self.check_post(form_data, '/day?date=2024-01-01&make_type=full', 302)
         todos = Todo.by_date(self.db_conn, '2024-01-01')
         todo1 = todos[1]
         self.assertEqual(todo1.id_, 2)
@@ -270,8 +270,9 @@ class TestsWithServer(TestCaseWithServer):
             return Todo.by_date(self.db_conn, '2024-01-01')[0]
         # test minimum
         self.post_process()
-        self.check_post({'day_comment': '', 'new_todo': 1},
-                        '/day?date=2024-01-01', 302)
+        self.check_post({'day_comment': '', 'new_todo': 1,
+                         'make_type': 'full'},
+                        '/day?date=2024-01-01&make_type=full', 302)
         # test posting to bad URLs
         self.check_post({}, '/todo=', 404)
         self.check_post({}, '/todo?id=', 400)
@@ -293,8 +294,9 @@ class TestsWithServer(TestCaseWithServer):
         self.check_post({'adopt': 1}, '/todo?id=1', 400)
         self.check_post({'adopt': 2}, '/todo?id=1', 404)
         # test posting second todo of same process
-        self.check_post({'day_comment': '', 'new_todo': 1},
-                        '/day?date=2024-01-01', 302)
+        self.check_post({'day_comment': '', 'new_todo': 1,
+                         'make_type': 'full'},
+                        '/day?date=2024-01-01&make_type=full', 302)
         # test todo 1 adopting todo 2
         todo1 = post_and_reload({'adopt': 2})
         todo2 = Todo.by_date(self.db_conn, '2024-01-01')[1]
@@ -319,10 +321,10 @@ class TestsWithServer(TestCaseWithServer):
         """Test Todos posted to Day view may adopt existing Todos."""
         form_data = self.post_process()
         form_data = self.post_process(2, form_data | {'new_top_step': 1})
-        form_data = {'day_comment': '', 'new_todo': 1}
-        self.check_post(form_data, '/day?date=2024-01-01', 302)
+        form_data = {'day_comment': '', 'new_todo': 1, 'make_type': 'full'}
+        self.check_post(form_data, '/day?date=2024-01-01&make_type=full', 302)
         form_data['new_todo'] = 2
-        self.check_post(form_data, '/day?date=2024-01-01', 302)
+        self.check_post(form_data, '/day?date=2024-01-01&make_type=full', 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, [])
@@ -334,8 +336,9 @@ class TestsWithServer(TestCaseWithServer):
         """Test multiple Todos can be posted to Day view."""
         form_data = self.post_process()
         form_data = self.post_process(2)
-        form_data = {'day_comment': '', 'new_todo': [1, 2]}
-        self.check_post(form_data, '/day?date=2024-01-01', 302)
+        form_data = {'day_comment': '', 'new_todo': [1, 2],
+                     'make_type': 'full'}
+        self.check_post(form_data, '/day?date=2024-01-01&make_type=full', 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.process.id_, 1)
@@ -349,8 +352,9 @@ class TestsWithServer(TestCaseWithServer):
             return t.process.id_
 
         def check_adoption(date: str, new_todos: list[int]) -> None:
-            form_data = {'day_comment': '', 'new_todo': new_todos}
-            self.check_post(form_data, f'/day?date={date}', 302)
+            form_data = {'day_comment': '', 'new_todo': new_todos,
+                         'make_type': 'full'}
+            self.check_post(form_data, f'/day?date={date}&make_type=full', 302)
             day_todos = Todo.by_date(self.db_conn, date)
             day_todos.sort(key=key_order_func)
             todo1 = day_todos[0]
@@ -368,8 +372,9 @@ class TestsWithServer(TestCaseWithServer):
             form_data['new_top_step'] = new_top_steps
             form_data['step_of'] = []
             form_data = self.post_process(process_id, form_data)
-            form_data = {'day_comment': '', 'new_todo': [process_id]}
-            self.check_post(form_data, f'/day?date={date}', 302)
+            form_data = {'day_comment': '', 'new_todo': [process_id],
+                         'make_type': 'full'}
+            self.check_post(form_data, f'/day?date={date}&make_type=full', 302)
             day_todos = Todo.by_date(self.db_conn, date)
             day_todos.sort(key=key_order_func, reverse=True)
             self.assertEqual(len(day_todos), 3)
@@ -393,21 +398,22 @@ class TestsWithServer(TestCaseWithServer):
     def test_do_POST_day_todo_doneness(self) -> None:
         """Test Todo doneness can be posted to Day view."""
         form_data = self.post_process()
-        form_data = {'day_comment': '', 'new_todo': [1]}
-        self.check_post(form_data, '/day?date=2024-01-01', 302)
+        form_data = {'day_comment': '', 'new_todo': [1], 'make_type': 'full'}
+        self.check_post(form_data, '/day?date=2024-01-01&make_type=full', 302)
         todo = Todo.by_date(self.db_conn, '2024-01-01')[0]
-        form_data = {'day_comment': '', 'todo_id': [1]}
-        self.check_post(form_data, '/day?date=2024-01-01', 302)
+        form_data = {'day_comment': '', 'todo_id': [1], 'make_type': 'full'}
+        self.check_post(form_data, '/day?date=2024-01-01&make_type=full', 302)
         self.assertEqual(todo.is_done, False)
-        form_data = {'day_comment': '', 'todo_id': [1], 'done': [1]}
-        self.check_post(form_data, '/day?date=2024-01-01', 302)
+        form_data = {'day_comment': '', 'todo_id': [1], 'done': [1],
+                     'make_type': 'full'}
+        self.check_post(form_data, '/day?date=2024-01-01&make_type=full', 302)
         self.assertEqual(todo.is_done, True)
 
     def test_do_GET_todo(self) -> None:
         """Test GET /todo response codes."""
         self.post_process()
-        form_data = {'day_comment': '', 'new_todo': 1}
-        self.check_post(form_data, '/day?date=2024-01-01', 302)
+        form_data = {'day_comment': '', 'new_todo': 1, 'make_type': 'full'}
+        self.check_post(form_data, '/day?date=2024-01-01&make_type=full', 302)
         self.check_get('/todo', 400)
         self.check_get('/todo?id=', 400)
         self.check_get('/todo?id=foo', 400)