From: Christian Heller Date: Fri, 9 Aug 2024 18:04:28 +0000 (+0200) Subject: Simplify do_POST_todo code. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bdb.prefix%7D%7D/%7B%7Bprefix%7D%7D/add_task?a=commitdiff_plain;h=9c615407aa166e6ce39aedde0ed45890aa87e58b;p=plomtask Simplify do_POST_todo code. --- diff --git a/plomtask/http.py b/plomtask/http.py index 51b35cb..704ae06 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -632,7 +632,7 @@ class TaskHandler(BaseHTTPRequestHandler): """Update Todo and its children.""" # pylint: disable=too-many-locals # pylint: disable=too-many-branches - adopted_child_ids = self._form.get_all_int('adopt') + adoptees = self._form.get_all_int('adopt') to_make = {'full': self._form.get_all_int('make_full'), 'empty': self._form.get_all_int('make_empty')} step_fillers = self._form.get_all_str('step_filler') @@ -670,19 +670,14 @@ class TaskHandler(BaseHTTPRequestHandler): elif filler.startswith('make_full_'): to_make['full'] += [target_id] else: - adopted_child_ids += [target_id] + adoptees += [target_id] # todo.set_condition_relations(self._conn, *cond_rels) - to_remove = [] - for child in todo.children: - if child.id_ and (child.id_ not in adopted_child_ids): - to_remove += [child.id_] - for id_ in to_remove: - child = Todo.by_id(self._conn, id_) - todo.remove_child(child) - for child_id in adopted_child_ids: - if child_id not in [c.id_ for c in todo.children]: - todo.add_child(Todo.by_id(self._conn, child_id)) + for child in [c for c in todo.children if c.id_ not in adoptees]: + todo.remove_child(child) + for child_id in [id_ for id_ in adoptees + if id_ not in [c.id_ for c in todo.children]]: + todo.add_child(Todo.by_id(self._conn, child_id)) todo.update_attrs(**to_update) for approach, proc_ids in to_make.items(): for process_id in proc_ids: @@ -749,7 +744,7 @@ class TaskHandler(BaseHTTPRequestHandler): # set relations to Conditions and ProcessSteps / other Processes process.set_condition_relations(self._conn, *cond_rels) owned_steps = [] - for step_id in kept_steps: # collecting sub-steps + for step_id in kept_steps: owned_steps += [ProcessStep.by_id(self._conn, step_id)] owned_steps += [ # new sub-steps ProcessStep(None, process.id_, step_process_id, step_id)