X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;ds=sidebyside;f=plomtask%2Fhttp.py;h=deadb21f88c65726aa7544c810922f2712600e36;hb=e825a876e82ffbedf0234f4dfb6d6055d9e29241;hp=b5a6c167b98f36c5b4ffb6e0c3d0ea14869101a7;hpb=010ef4bfea17be7436a937f28e7b54d3da17a1e1;p=plomtask diff --git a/plomtask/http.py b/plomtask/http.py index b5a6c16..deadb21 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -1,5 +1,6 @@ """Web server stuff.""" from typing import Any +from collections import namedtuple from http.server import BaseHTTPRequestHandler from http.server import HTTPServer from urllib.parse import urlparse, parse_qs @@ -119,23 +120,22 @@ class TaskHandler(BaseHTTPRequestHandler): def do_GET_day(self) -> dict[str, object]: """Show single Day of ?date=.""" date = self.params.get_str('date', todays_date()) - conditions_listing = [] top_todos = [t for t in Todo.by_date(self.conn, date) if not t.parents] seen_todos: set[int] = set() seen_conditions: set[int] = set() todo_trees = [t.get_step_tree(seen_todos, seen_conditions) for t in top_todos] - for condition in Condition.all(self.conn): - enablers = Todo.enablers_for_at(self.conn, condition, date) - disablers = Todo.disablers_for_at(self.conn, condition, date) - conditions_listing += [{ - 'condition': condition, - 'enablers': enablers, - 'disablers': disablers}] + ConditionsNode = namedtuple('ConditionsNode', + ('condition', 'enablers', 'disablers')) + conditions_nodes: list[ConditionsNode] = [] + for condi in Condition.all(self.conn): + enablers = Todo.enablers_for_at(self.conn, condi, date) + disablers = Todo.disablers_for_at(self.conn, condi, date) + conditions_nodes += [ConditionsNode(condi, enablers, disablers)] return {'day': Day.by_id(self.conn, date, create=True), 'todo_trees': todo_trees, 'processes': Process.all(self.conn), - 'conditions_listing': conditions_listing} + 'conditions_nodes': conditions_nodes} def do_GET_todo(self) -> dict[str, object]: """Show single Todo of ?id=.""" @@ -161,7 +161,7 @@ class TaskHandler(BaseHTTPRequestHandler): return {'process': process, 'steps': process.get_steps(self.conn), 'owners': process.used_as_step_by(self.conn), - 'process_candidates': Process.all(self.conn), + 'step_candidates': Process.all(self.conn), 'condition_candidates': Condition.all(self.conn)} def do_GET_processes(self) -> dict[str, object]: @@ -195,11 +195,13 @@ class TaskHandler(BaseHTTPRequestHandler): day = Day.by_id(self.conn, date, create=True) day.comment = self.form_data.get_str('comment') day.save(self.conn) - process_id = self.form_data.get_int_or_none('new_todo') - if process_id is not None: + existing_todos = Todo.by_date(self.conn, date) + for process_id in self.form_data.get_all_int('new_todo'): process = Process.by_id(self.conn, process_id) todo = Todo(None, process, False, day.date) todo.save(self.conn) + todo.adopt_from(existing_todos) + todo.save(self.conn) def do_POST_todo(self) -> None: """Update Todo and its children."""