home · contact · privacy
Simplify do_POST_todo code. master
authorChristian Heller <c.heller@plomlompom.de>
Fri, 9 Aug 2024 18:04:28 +0000 (20:04 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 9 Aug 2024 18:04:28 +0000 (20:04 +0200)
plomtask/http.py

index 51b35cb9722d60e50ba1eb679960a1c0c06725bd..704ae06f5e9f5c43dd059c040a01d72af0a8e64e 100644 (file)
@@ -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)