From: Christian Heller Date: Mon, 5 Aug 2024 07:07:33 +0000 (+0200) Subject: Improve readability of do_POST_process handler code. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/static/%7B%7Bdb.prefix%7D%7D/templates?a=commitdiff_plain;h=e7256be2e49b9d784d920e711f584b3e4d658358;p=plomtask Improve readability of do_POST_process handler code. --- diff --git a/plomtask/http.py b/plomtask/http.py index fa04579..b10ce3a 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -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