From: Christian Heller Date: Sat, 13 Apr 2024 02:43:07 +0000 (+0200) Subject: Minor refactoring. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/%27%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28escapeHTML%28span%5B2%5D%29%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28%27?a=commitdiff_plain;h=a0fc8b9ddabe3af5b2cc0592513ba3e69d5fd9d4;p=plomtask Minor refactoring. --- 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: