X-Git-Url: https://plomlompom.com/repos/day?a=blobdiff_plain;f=plomtask%2Fhttp.py;h=f6b17a076c6fa92455983b1198351cc486c79906;hb=ad957773a676d94f523199e7fc46fa416224a09f;hp=484147239ae8f3ef91d2ece69458d4b94c27e596;hpb=85c260d1416340274b954175a69563868f481bc5;p=plomtask diff --git a/plomtask/http.py b/plomtask/http.py index 4841472..f6b17a0 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -152,6 +152,41 @@ class TaskHandler(BaseHTTPRequestHandler): 'todo_candidates': Todo.by_date(self.conn, todo.date), 'condition_candidates': Condition.all(self.conn)} + def do_GET_todos(self) -> dict[str, object]: + """Show Todos from ?start= to ?end=, of ?process=, ?comment= pattern""" + sort_by = self.params.get_str('sort_by') + start = self.params.get_str('start') + end = self.params.get_str('end') + process_id = self.params.get_int_or_none('process_id') + comment_pattern = self.params.get_str('comment_pattern') + todos = [] + for t in Todo.matching(self.conn, comment_pattern): + # pylint: disable=too-many-boolean-expressions + if (start and t.date < start)\ + or (end and t.date > end)\ + or (process_id and t.process.id_ != process_id): + continue + todos += [t] + if sort_by == 'doneness': + todos.sort(key=lambda t: t.is_done) + elif sort_by == '-doneness': + todos.sort(key=lambda t: t.is_done, reverse=True) + elif sort_by == 'process': + todos.sort(key=lambda t: t.process.title.newest) + elif sort_by == '-process': + todos.sort(key=lambda t: t.process.title.newest, reverse=True) + elif sort_by == 'comment': + todos.sort(key=lambda t: t.comment) + elif sort_by == '-comment': + todos.sort(key=lambda t: t.comment, reverse=True) + elif sort_by == '-date': + todos.sort(key=lambda t: t.date, reverse=True) + else: + todos.sort(key=lambda c: c.title.newest) + return {'start': start, 'end': end, 'process_id': process_id, + 'comment_pattern': comment_pattern, 'todos': todos, + 'all_processes': Process.all(self.conn), 'sort_by': sort_by} + def do_GET_conditions(self) -> dict[str, object]: """Show all Conditions.""" pattern = self.params.get_str('pattern') @@ -193,6 +228,7 @@ class TaskHandler(BaseHTTPRequestHandler): return {'process': process, 'steps': process.get_steps(self.conn), 'owners': process.used_as_step_by(self.conn), + 'n_todos': len(Todo.by_process_id(self.conn, process.id_)), 'step_candidates': Process.all(self.conn), 'condition_candidates': Condition.all(self.conn)} @@ -256,21 +292,8 @@ class TaskHandler(BaseHTTPRequestHandler): day = Day.by_id(self.conn, date, create=True) day.comment = self.form_data.get_str('day_comment') day.save(self.conn) - new_todos = [] - 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) - new_todos += [todo] - adopted = True - while adopted: - adopted = False - existing_todos = Todo.by_date(self.conn, date) - for todo in new_todos: - if todo.adopt_from(existing_todos): - adopted = True - todo.make_missing_children(self.conn) - todo.save(self.conn) + Todo.create_with_children(self.conn, date, + self.form_data.get_all_int('new_todo')) done_ids = self.form_data.get_all_int('done') comments = self.form_data.get_all_str('comment') efforts = self.form_data.get_all_str('effort') @@ -341,8 +364,10 @@ class TaskHandler(BaseHTTPRequestHandler): process.set_disables(self.conn, self.form_data.get_all_int('disables')) process.calendarize = self.form_data.get_all_str('calendarize') != [] process.save(self.conn) - process.explicit_steps = [] steps: list[tuple[int | None, int, int | None]] = [] + for step_id in self.form_data.get_all_int('keep_step'): + if step_id not in self.form_data.get_all_int('steps'): + raise BadFormatException('trying to keep unknown step') 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}'):