From a0fc8b9ddabe3af5b2cc0592513ba3e69d5fd9d4 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Sat, 13 Apr 2024 04:43:07 +0200 Subject: [PATCH] Minor refactoring. --- plomtask/http.py | 7 +------ plomtask/todos.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/plomtask/http.py b/plomtask/http.py index 5a7126e..5d165ec 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -209,12 +209,7 @@ class TaskHandler(BaseHTTPRequestHandler): if child_id is not None: child = Todo.by_id(conn, child_id) todo.add_child(child) - if len(form_data.get_all_str('done')) > 0: - if not todo.is_doable: - raise BadFormatException('cannot set undoable Todo to done') - todo.is_done = True - else: - todo.is_done = False + todo.is_done = len(form_data.get_all_str('done')) > 0 todo.save(conn) def do_POST_process(self, conn: DatabaseConnection, params: ParamsParser, diff --git a/plomtask/todos.py b/plomtask/todos.py index 43ada0b..8fa3b91 100644 --- a/plomtask/todos.py +++ b/plomtask/todos.py @@ -15,7 +15,7 @@ class Todo: is_done: bool, day: Day) -> None: self.id_ = id_ self.process = process - self.is_done = is_done + self._is_done = is_done self.day = day self.children: list[Todo] = [] self.parents: list[Todo] = [] @@ -69,6 +69,17 @@ class Todo: return False return True + @property + def is_done(self) -> bool: + """Wrapper around self._is_done so we can control its setter.""" + return self._is_done + + @is_done.setter + def is_done(self, value: bool) -> None: + if value != self.is_done and not self.is_doable: + raise BadFormatException('cannot change doneness of undoable Todo') + self._is_done = value + def add_child(self, child: Todo) -> None: """Add child to self.children, guard against recursion""" def walk_steps(node: Todo) -> None: -- 2.30.2