home · contact · privacy
Improve readability of do_POST_process handler code.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 5 Aug 2024 07:07:33 +0000 (09:07 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 5 Aug 2024 07:07:33 +0000 (09:07 +0200)
plomtask/http.py

index fa045791882d6151fe98c9a331dfa7cab2c01a2e..b10ce3a2bb7bd9862586e85e314d80d1a9b7625c 100644 (file)
@@ -722,10 +722,10 @@ class TaskHandler(BaseHTTPRequestHandler):
         calendarize = self._form_data.get_bool('calendarize')
         step_of = self._form_data.get_all_str('step_of')
         suppresses = self._form_data.get_all_int('suppresses')
-        step_ids = self._form_data.get_all_int('kept_steps')
+        kept_steps = self._form_data.get_all_int('kept_steps')
         new_top_steps = self._form_data.get_all_str('new_top_step')
         new_steps_to = {}
-        for step_id in step_ids:
+        for step_id in kept_steps:
             name = f'new_step_to_{step_id}'
             new_steps_to[step_id] = self._form_data.get_all_int(name)
         for k, v in versioned.items():
@@ -735,6 +735,11 @@ class TaskHandler(BaseHTTPRequestHandler):
         process.save(self.conn)
         assert isinstance(process.id_, int)
         # set relations to, and if non-existant yet: create, other Processes
+        # pylint: disable=fixme
+        # TODO: in what order to set owners, owneds, and possibly step
+        # suppressions can make the difference between recursion checks
+        # failing; should probably be handled class-internally to Process
+        # rather than here!
         # 1. owners (upwards)
         owners_to_set = []
         new_owner_title = None
@@ -747,18 +752,19 @@ class TaskHandler(BaseHTTPRequestHandler):
         # 2. owneds (downwards)
         new_step_title = None
         steps: list[ProcessStep] = [ProcessStep.by_id(self.conn, step_id)
-                                    for step_id in step_ids]
-        for step_id in step_ids:
-            new = [ProcessStep(None, process.id_, step_process_id, step_id)
-                   for step_process_id in new_steps_to[step_id]]
-            steps += new
-        for step_identifier in new_top_steps:
+                                    for step_id in kept_steps]
+        for step_id in kept_steps:
+            new_sub_steps = [
+                    ProcessStep(None, process.id_, step_process_id, step_id)
+                    for step_process_id in new_steps_to[step_id]]
+            steps += new_sub_steps
+        for step_id_or_new_title in new_top_steps:
             try:
-                step_process_id = int(step_identifier)
+                step_process_id = int(step_id_or_new_title)
                 step = ProcessStep(None, process.id_, step_process_id, None)
                 steps += [step]
             except ValueError:
-                new_step_title = step_identifier
+                new_step_title = step_id_or_new_title
         process.set_steps(self.conn, steps)
         process.set_step_suppressions(self.conn, suppresses)
         # encode titles for potentially newly created Processes up or down