X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D/cards/%7B%7Bcard_id%7D%7D/static/gitweb.js?a=blobdiff_plain;f=plomtask%2Fhttp.py;h=b5a6c167b98f36c5b4ffb6e0c3d0ea14869101a7;hb=010ef4bfea17be7436a937f28e7b54d3da17a1e1;hp=4bf58b41a2cb264a0a40bf018ee9c5536e358bda;hpb=8f6b4ec61b126d6edbfda4f20d62398d92390a95;p=plomtask diff --git a/plomtask/http.py b/plomtask/http.py index 4bf58b4..b5a6c16 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -120,6 +120,11 @@ class TaskHandler(BaseHTTPRequestHandler): """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) @@ -128,7 +133,7 @@ class TaskHandler(BaseHTTPRequestHandler): 'enablers': enablers, 'disablers': disablers}] return {'day': Day.by_id(self.conn, date, create=True), - 'todos': Todo.by_date(self.conn, date), + 'todo_trees': todo_trees, 'processes': Process.all(self.conn), 'conditions_listing': conditions_listing} @@ -200,8 +205,15 @@ class TaskHandler(BaseHTTPRequestHandler): """Update Todo and its children.""" id_ = self.params.get_int('id') todo = Todo.by_id(self.conn, id_) - child_id = self.form_data.get_int_or_none('adopt') - if child_id is not None: + adopted_child_ids = self.form_data.get_all_int('adopt') + for child in todo.children: + if child.id_ not in adopted_child_ids: + assert isinstance(child.id_, int) + child = Todo.by_id(self.conn, child.id_) + todo.remove_child(child) + for child_id in adopted_child_ids: + if child_id in [c.id_ for c in todo.children]: + continue child = Todo.by_id(self.conn, child_id) todo.add_child(child) todo.set_conditions(self.conn, self.form_data.get_all_int('condition'))