X-Git-Url: https://plomlompom.com/repos/feed.xml?a=blobdiff_plain;f=plomtask%2Fhttp.py;h=e541057ed793ebe2a53c55b50a11be7133c5884f;hb=54e6c8bccace28583cf9926aa00917a796628a00;hp=cb00825d469989935f88cdd97132cc96f69b1492;hpb=e32eec3a22d7e823c5763ba718c820adc9418633;p=plomtask diff --git a/plomtask/http.py b/plomtask/http.py index cb00825..e541057 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) @@ -127,17 +132,17 @@ class TaskHandler(BaseHTTPRequestHandler): 'condition': condition, 'enablers': enablers, 'disablers': disablers}] - return {'day': Day.by_date(self.conn, date, create=True), - 'todos': Todo.by_date(self.conn, date), + return {'day': Day.by_id(self.conn, date, create=True), + 'todo_trees': todo_trees, 'processes': Process.all(self.conn), 'conditions_listing': conditions_listing} def do_GET_todo(self) -> dict[str, object]: """Show single Todo of ?id=.""" - id_ = self.params.get_int_or_none('id') + id_ = self.params.get_int('id') todo = Todo.by_id(self.conn, id_) return {'todo': todo, - 'todo_candidates': Todo.by_date(self.conn, todo.day.date), + 'todo_candidates': Todo.by_date(self.conn, todo.date), 'condition_candidates': Condition.all(self.conn)} def do_GET_conditions(self) -> dict[str, object]: @@ -187,31 +192,31 @@ class TaskHandler(BaseHTTPRequestHandler): def do_POST_day(self) -> None: """Update or insert Day of date and Todos mapped to it.""" date = self.params.get_str('date') - day = Day.by_date(self.conn, date, create=True) + 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: process = Process.by_id(self.conn, process_id) - todo = Todo(None, process, False, day) + todo = Todo(None, process, False, day.date) todo.save(self.conn) def do_POST_todo(self) -> None: """Update Todo and its children.""" - id_ = self.params.get_int_or_none('id') + 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: child = Todo.by_id(self.conn, child_id) todo.add_child(child) todo.set_conditions(self.conn, self.form_data.get_all_int('condition')) - todo.set_fulfills(self.conn, self.form_data.get_all_int('fulfills')) - todo.set_undoes(self.conn, self.form_data.get_all_int('undoes')) + todo.set_enables(self.conn, self.form_data.get_all_int('enables')) + todo.set_disables(self.conn, self.form_data.get_all_int('disables')) todo.is_done = len(self.form_data.get_all_str('done')) > 0 todo.save(self.conn) - for condition in todo.fulfills: + for condition in todo.enables: condition.save(self.conn) - for condition in todo.undoes: + for condition in todo.disables: condition.save(self.conn) def do_POST_process(self) -> None: @@ -223,25 +228,27 @@ class TaskHandler(BaseHTTPRequestHandler): process.effort.set(self.form_data.get_float('effort')) process.set_conditions(self.conn, self.form_data.get_all_int('condition')) - process.set_fulfills(self.conn, self.form_data.get_all_int('fulfills')) - process.set_undoes(self.conn, self.form_data.get_all_int('undoes')) - process.save_without_steps(self.conn) + process.set_enables(self.conn, self.form_data.get_all_int('enables')) + process.set_disables(self.conn, self.form_data.get_all_int('disables')) + process.save_core(self.conn) assert process.id_ is not None # for mypy process.explicit_steps = [] + steps: list[tuple[int | None, int, int | None]] = [] for step_id in self.form_data.get_all_int('steps'): - for step_process_id in\ - self.form_data.get_all_int(f'new_step_to_{step_id}'): - process.add_step(self.conn, None, step_process_id, step_id) + for step_process_id in self.form_data.get_all_int( + f'new_step_to_{step_id}'): + steps += [(None, step_process_id, step_id)] if step_id not in self.form_data.get_all_int('keep_step'): continue step_process_id = self.form_data.get_int( f'step_{step_id}_process_id') parent_id = self.form_data.get_int_or_none( f'step_{step_id}_parent_id') - process.add_step(self.conn, step_id, step_process_id, parent_id) + steps += [(step_id, step_process_id, parent_id)] for step_process_id in self.form_data.get_all_int('new_top_step'): - process.add_step(self.conn, None, step_process_id, None) - process.fix_steps(self.conn) + steps += [(None, step_process_id, None)] + process.set_steps(self.conn, steps) + process.save(self.conn) def do_POST_condition(self) -> None: """Update/insert Condition of ?id= and fields defined in postvars."""