X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/ledger2?a=blobdiff_plain;f=plomtask%2Fhttp.py;h=5a7126e3232176630d78ddd43b10bb659c425e94;hb=aed1d5968abf97976db3725347fe4e7672c935e7;hp=91c3224eb0369e81b9e146970f4b548781ecb8d4;hpb=982d712cbf12acde21ce448e0d1ed28468f1c90e;p=plomtask diff --git a/plomtask/http.py b/plomtask/http.py index 91c3224..5a7126e 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -146,10 +146,10 @@ class TaskHandler(BaseHTTPRequestHandler): ParamsParser) -> str: """Show single Todo of ?id=.""" id_ = params.get_int_or_none('id') - if id_ is None: - raise NotFoundException('Todo of ID not found.') todo = Todo.by_id(conn, id_) - return self.server.jinja.get_template('todo.html').render(todo=todo) + candidates = Todo.by_date(conn, todo.day.date) + return self.server.jinja.get_template('todo.html').render( + todo=todo, candidates=candidates) def do_GET_process(self, conn: DatabaseConnection, params: ParamsParser) -> str: @@ -175,7 +175,7 @@ class TaskHandler(BaseHTTPRequestHandler): postvars = parse_qs(self.rfile.read(length).decode(), keep_blank_values=True, strict_parsing=True) form_data = PostvarsParser(postvars) - if site in ('day', 'process'): + if site in ('day', 'process', 'todo'): getattr(self, f'do_POST_{site}')(conn, params, form_data) conn.commit() else: @@ -200,6 +200,23 @@ class TaskHandler(BaseHTTPRequestHandler): todo = Todo(None, process, False, day) todo.save(conn) + def do_POST_todo(self, conn: DatabaseConnection, params: ParamsParser, + form_data: PostvarsParser) -> None: + """Update Todo and its children.""" + id_ = params.get_int_or_none('id') + todo = Todo.by_id(conn, id_) + child_id = form_data.get_int_or_none('adopt') + 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.save(conn) + def do_POST_process(self, conn: DatabaseConnection, params: ParamsParser, form_data: PostvarsParser) -> None: """Update or insert Process of ?id= and fields defined in postvars."""