From 5383b5cf1520a1cb66b4966dd4ee449a99f5e465 Mon Sep 17 00:00:00 2001 From: Christian Heller <c.heller@plomlompom.de> Date: Thu, 30 May 2024 06:12:35 +0200 Subject: [PATCH] Display historical VersionedAttributes where it makes sense. --- plomtask/http.py | 14 +++++++------- plomtask/todos.py | 14 ++++++++++++++ plomtask/versioned_attributes.py | 2 ++ templates/_macros.html | 4 ++-- templates/calendar.html | 2 +- templates/day.html | 10 +++++----- templates/todo.html | 16 ++++++++-------- templates/todos.html | 2 +- 8 files changed, 40 insertions(+), 24 deletions(-) diff --git a/plomtask/http.py b/plomtask/http.py index f6b17a0..8255aa2 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -172,9 +172,9 @@ class TaskHandler(BaseHTTPRequestHandler): elif sort_by == '-doneness': todos.sort(key=lambda t: t.is_done, reverse=True) elif sort_by == 'process': - todos.sort(key=lambda t: t.process.title.newest) + todos.sort(key=lambda t: t.title_then) elif sort_by == '-process': - todos.sort(key=lambda t: t.process.title.newest, reverse=True) + todos.sort(key=lambda t: t.title_then, reverse=True) elif sort_by == 'comment': todos.sort(key=lambda t: t.comment) elif sort_by == '-comment': @@ -182,7 +182,7 @@ class TaskHandler(BaseHTTPRequestHandler): elif sort_by == '-date': todos.sort(key=lambda t: t.date, reverse=True) else: - todos.sort(key=lambda c: c.title.newest) + todos.sort(key=lambda t: t.date) return {'start': start, 'end': end, 'process_id': process_id, 'comment_pattern': comment_pattern, 'todos': todos, 'all_processes': Process.all(self.conn), 'sort_by': sort_by} @@ -256,13 +256,13 @@ class TaskHandler(BaseHTTPRequestHandler): processes = Process.matching(self.conn, pattern) sort_by = self.params.get_str('sort_by') if sort_by == 'steps': - processes.sort(key=lambda c: len(c.explicit_steps)) + processes.sort(key=lambda p: len(p.explicit_steps)) elif sort_by == '-steps': - processes.sort(key=lambda c: len(c.explicit_steps), reverse=True) + processes.sort(key=lambda p: len(p.explicit_steps), reverse=True) elif sort_by == '-title': - processes.sort(key=lambda c: c.title.newest, reverse=True) + processes.sort(key=lambda p: p.title.newest, reverse=True) else: - processes.sort(key=lambda c: c.title.newest) + processes.sort(key=lambda p: p.title.newest) return {'processes': processes, 'sort_by': sort_by, 'pattern': pattern} def do_POST(self) -> None: diff --git a/plomtask/todos.py b/plomtask/todos.py index 712609a..ffef677 100644 --- a/plomtask/todos.py +++ b/plomtask/todos.py @@ -182,6 +182,20 @@ class Todo(BaseModel[int], ConditionsRelations): """Shortcut to .process.title.""" return self.process.title + @property + def title_then(self) -> str: + """Shortcut to .process.title.at(self.date)""" + title_then = self.process.title.at(self.date) + assert isinstance(title_then, str) + return title_then + + @property + def effort_then(self) -> float: + """Shortcut to .process.effort.at(self.date)""" + effort_then = self.process.effort.at(self.date) + assert isinstance(effort_then, float) + return effort_then + def adopt_from(self, todos: list[Todo]) -> bool: """As far as possible, fill unsatisfied dependencies from todos.""" adopted = False diff --git a/plomtask/versioned_attributes.py b/plomtask/versioned_attributes.py index 1810a31..b3442d7 100644 --- a/plomtask/versioned_attributes.py +++ b/plomtask/versioned_attributes.py @@ -51,6 +51,8 @@ class VersionedAttribute: def at(self, queried_time: str) -> str | float: """Retrieve value of timestamp nearest queried_time from the past.""" + if len(queried_time) == 10: + queried_time += ' 23:59:59.999' sorted_timestamps = sorted(self.history.keys()) if 0 == len(sorted_timestamps): return self.default diff --git a/templates/_macros.html b/templates/_macros.html index 25d94c5..b1f0104 100644 --- a/templates/_macros.html +++ b/templates/_macros.html @@ -17,7 +17,7 @@ -{% macro simple_checkbox_table(title, items, type_name, list_name, add_string="add") %} +{% macro simple_checkbox_table(title, items, type_name, list_name, add_string="add", historical=false) %} <table> {% for item in items %} <tr> @@ -25,7 +25,7 @@ <input type="checkbox" name="{{title}}" value="{{item.id_}}" checked /> </td> <td> -<a href="{{type_name}}?id={{item.id_}}">{{item.title.newest|e}}</a> +<a href="{{type_name}}?id={{item.id_}}">{% if historical %}{{item.title_then}}{% else %}{{item.title.newest|e}}{% endif %}</a> </td> </tr> {% endfor %} diff --git a/templates/calendar.html b/templates/calendar.html index 7724203..4d67242 100644 --- a/templates/calendar.html +++ b/templates/calendar.html @@ -52,7 +52,7 @@ to <input name="end" value="{{end}}" /> {% for todo in day.calendarized_todos %} <tr> <td>[{% if todo.is_done %}X{% else %} {% endif %}]</td> -<td><a href="todo?id={{todo.id_}}">{{todo.title.newest|e}}</td> +<td><a href="todo?id={{todo.id_}}">{{todo.title_then|e}}</td> <td>{{todo.comment|e}}</td> </tr> {% endfor %} diff --git a/templates/day.html b/templates/day.html index 6954fd3..2e1a380 100644 --- a/templates/day.html +++ b/templates/day.html @@ -47,11 +47,11 @@ td.todo_line { <td class="todo_line">{% if node.todo.effort %}{{ node.todo.effort }}{% endif %}</td> {% else %} <td class="todo_line"><input name="done" type="checkbox" value="{{node.todo.id_}}" {% if not node.todo.is_doable %}disabled{% endif %}/></td> -<td class="todo_line"><input name="effort" type="number" step=0.1 size=5 placeholder={{node.todo.process.effort.newest }} value={{node.todo.effort}} /></td> +<td class="todo_line"><input name="effort" type="number" step=0.1 size=5 placeholder={{node.todo.effort_then}} value={{node.todo.effort}} /></td> {% endif %} <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 %} +{% if node.seen %}({% endif %}<a href="todo?id={{node.todo.id_}}">{{node.todo.title_then|e}}</a>{% if node.seen %}){% endif %} </td> <td class="todo_line">-></td> @@ -86,7 +86,7 @@ td.todo_line { <tr> {% if path|length > 0 and not path[-1].todo.is_done %} <td> -({% for path_node in path %}<a href="todo?id={{path_node.todo.id_}}">{{path_node.todo.process.title.newest|e}}</a> <- {% endfor %}) +({% for path_node in path %}<a href="todo?id={{path_node.todo.id_}}">{{path_node.todo.title_then|e}}</a> <- {% endfor %}) </td> </tr> @@ -97,7 +97,7 @@ td.todo_line { <td> {% for i in range(indent) %} {% endfor %} + {% endif %} -{% if node.seen %}({% endif %}<a href="todo?id={{node.todo.id_}}">{{node.todo.process.title.newest|e}}</a> {% if node.todo.comment|length > 0 %}[{{node.todo.comment|e}}]{% endif %}{% if node.seen %}){% endif %} +{% if node.seen %}({% endif %}<a href="todo?id={{node.todo.id_}}">{{node.todo.title_then|e}}</a> {% if node.todo.comment|length > 0 %}[{{node.todo.comment|e}}]{% endif %}{% if node.seen %}){% endif %} </td> </tr> @@ -150,7 +150,7 @@ add todo: <input name="new_todo" list="processes" autocomplete="off" /> {% endfor %} <td class="cond_line_{{loop.index0 % 3}}">[{% if condition.is_active %}X{% else %} {% endif %}]</td> -<td colspan=4 class="cond_line_{{loop.index0 % 3}}"><a href="condition?id={{condition.id_}}">{{condition.title.newest|e}}</a></td> +<td colspan=4 class="cond_line_{{loop.index0 % 3}}"><a href="condition?id={{condition.id_}}">{{condition.title.at(day.date)|e}}</a></td> {% for _ in conditions_present %} {% if outer_loop.index0 + loop.index0 < conditions_present|length %} diff --git a/templates/todo.html b/templates/todo.html index a711568..41d894b 100644 --- a/templates/todo.html +++ b/templates/todo.html @@ -4,7 +4,7 @@ {% block content %} -<h3>Todo: {{todo.process.title.newest|e}}</h3> +<h3>Todo: {{todo.title_then|e}}</h3> <form action="todo?id={{todo.id_}}" method="POST"> <table> @@ -25,7 +25,7 @@ <tr> <th>effort</th> -<td><input type="number" name="effort" step=0.1 size=5 placeholder={{todo.process.effort.newest }} value={{ todo.effort }} /><br /></td> +<td><input type="number" name="effort" step=0.1 size=5 placeholder={{todo.effort_then}} value={{todo.effort}} /><br /></td> </tr> <tr> @@ -40,36 +40,36 @@ <tr> <th>conditions</th> -<td>{{ macros.simple_checkbox_table("condition", todo.conditions, "condition", "condition_candidates") }}</td> +<td>{{ macros.simple_checkbox_table("condition", todo.conditions, "condition", "condition_candidates", historical=true) }}</td> </tr> <tr> <th>blockers</th> -<td>{{ macros.simple_checkbox_table("blocker", todo.blockers, "condition", "condition_candidates") }}</td> +<td>{{ macros.simple_checkbox_table("blocker", todo.blockers, "condition", "condition_candidates", historical=true) }}</td> </tr> <tr> <th>enables</th> -<td>{{ macros.simple_checkbox_table("enables", todo.enables, "condition", "condition_candidates") }}</td> +<td>{{ macros.simple_checkbox_table("enables", todo.enables, "condition", "condition_candidates", historical=true) }}</td> </tr> <tr> <th>disables</th> -<td>{{ macros.simple_checkbox_table("disables", todo.disables, "condition", "condition_candidates") }}</td> +<td>{{ macros.simple_checkbox_table("disables", todo.disables, "condition", "condition_candidates", historical=true) }}</td> </tr> <tr> <th>parents</th> <td> {% for parent in todo.parents %} -<a href="todo?id={{parent.id_}}">{{parent.process.title.newest|e}}</a><br /> +<a href="todo?id={{parent.id_}}">{{parent.title_then|e}}</a><br /> {% endfor %} </td> </tr> <tr> <th>children</th> -<td>{{ macros.simple_checkbox_table("adopt", todo.children, "adopt", "todo_candidates", "adopt") }}</td> +<td>{{ macros.simple_checkbox_table("adopt", todo.children, "adopt", "todo_candidates", "adopt", true) }}</td> </tr> </table> diff --git a/templates/todos.html b/templates/todos.html index 54ac6f5..6cbf0bc 100644 --- a/templates/todos.html +++ b/templates/todos.html @@ -26,7 +26,7 @@ in comment <input name="comment_pattern" value="{{comment_pattern}}" /> <tr> <td>[{% if todo.is_done %}x{% else %} {% endif %}]</td> <td><a href="{{todo.date}}">{{todo.date}}</a></td> -<td><a href="process?id={{todo.process.id_}}">{{todo.process.title.newest}}</a></td> +<td><a href="process?id={{todo.process.id_}}">{{todo.title_then}}</a></td> <td><a href="{{todo.comment}}">{{todo.comment}}</a></td> </tr> {% endfor %} -- 2.30.2