From: Christian Heller <c.heller@plomlompom.de>
Date: Wed, 15 May 2024 02:37:08 +0000 (+0200)
Subject: Re-introduce POSTing of Todo doneness on Day view.
X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/blog?a=commitdiff_plain;h=206a9111fdc95fcb24ae4793a7536e1facf82b71;p=taskplom
Re-introduce POSTing of Todo doneness on Day view.
---
diff --git a/plomtask/http.py b/plomtask/http.py
index d411124..cf3288a 100644
--- a/plomtask/http.py
+++ b/plomtask/http.py
@@ -211,9 +211,10 @@ class TaskHandler(BaseHTTPRequestHandler):
adopted = True
todo.make_missing_children(self.conn)
todo.save(self.conn)
- for todo_id in self.form_data.get_all_int('done'):
+ done_ids = self.form_data.get_all_int('done')
+ for todo_id in self.form_data.get_all_int('todo_id'):
todo = Todo.by_id(self.conn, todo_id)
- todo.is_done = True
+ todo.is_done = todo_id in done_ids
todo.save(self.conn)
for condition in todo.enables:
condition.save(self.conn)
diff --git a/templates/day.html b/templates/day.html
index 167b703..cd683da 100644
--- a/templates/day.html
+++ b/templates/day.html
@@ -32,13 +32,14 @@ td.todo_line {
{% macro show_node_undone(node, indent) %}
{% if not node.todo.is_done %}
<tr>
+<input type="hidden" name="todo_id" value="{{node.todo.id_}}" />
{% for condition in conditions_present %}
<td class="cond_line_{{loop.index0 % 3}} {% if not condition.is_active %}min_width{% endif %}">{% if condition in node.todo.conditions %}{% if not condition.is_active %}O{% endif %}{% endif %}</td>
{% endfor %}
<td class="todo_line">-></td>
-<td class="todo_line"><input name="done" type="checkbox" {% if node.todo.is_done %}checked disabled{% endif %} {% if not node.todo.is_doable %}disabled{% endif %}/></td>
+<td class="todo_line"><input name="done" type="checkbox" value="{{node.todo.id_}}" {% if node.todo.is_done %}checked disabled{% endif %} {% if not node.todo.is_doable %}disabled{% endif %}/></td>
<td class="todo_line">
{% for i in range(indent) %} {% endfor %} +
{% if node.seen %}({% endif %}<a href="todo?id={{node.todo.id_}}">{{node.todo.process.title.newest|e}}</a>{% if node.seen %}){% endif %}
diff --git a/tests/todos.py b/tests/todos.py
index 5e9f4b8..0633547 100644
--- a/tests/todos.py
+++ b/tests/todos.py
@@ -357,6 +357,19 @@ class TestsWithServer(TestCaseWithServer):
self.assertEqual(todo2.children, [todo1])
self.assertEqual(todo2.parents, [])
+ def test_do_POST_day_todo_doneness(self) -> None:
+ """Test multiple Todos can be posted to Day view."""
+ form_data = self.post_process()
+ form_data = {'comment': '', 'new_todo': [1]}
+ self.check_post(form_data, '/day?date=2024-01-01', 302)
+ todo = Todo.by_date(self.db_conn, '2024-01-01')[0]
+ form_data = {'comment': '', 'todo_id': [1]}
+ self.check_post(form_data, '/day?date=2024-01-01', 302)
+ self.assertEqual(todo.is_done, False)
+ form_data = {'comment': '', 'todo_id': [1], 'done': [1]}
+ self.check_post(form_data, '/day?date=2024-01-01', 302)
+ self.assertEqual(todo.is_done, True)
+
def test_do_GET_todo(self) -> None:
"""Test GET /todo response codes."""
self.post_process()