+ @_delete_or_post(Process, '/processes')
+ def do_POST_process(self, process: Process) -> str:
+ """Update or insert Process of ?id= and fields defined in postvars."""
+ # pylint: disable=too-many-locals
+ # pylint: disable=too-many-statements
+ title = self._form_data.get_str('title')
+ description = self._form_data.get_str('description')
+ effort = self._form_data.get_float('effort')
+ conditions = self._form_data.get_all_int('conditions')
+ blockers = self._form_data.get_all_int('blockers')
+ enables = self._form_data.get_all_int('enables')
+ disables = self._form_data.get_all_int('disables')
+ calendarize = self._form_data.get_all_str('calendarize') != []
+ suppresses = self._form_data.get_all_int('suppresses')
+ step_of = self._form_data.get_all_str('step_of')
+ keep_steps = self._form_data.get_all_int('keep_step')
+ step_ids = self._form_data.get_all_int('steps')
+ new_top_steps = self._form_data.get_all_str('new_top_step')
+ step_process_id_to = {}
+ step_parent_id_to = {}
+ new_steps_to = {}
+ for step_id in step_ids:
+ name = f'new_step_to_{step_id}'
+ new_steps_to[step_id] = self._form_data.get_all_int(name)
+ for step_id in keep_steps:
+ name = f'step_{step_id}_process_id'
+ step_process_id_to[step_id] = self._form_data.get_int(name)
+ name = f'step_{step_id}_parent_id'
+ step_parent_id_to[step_id] = self._form_data.get_int_or_none(name)
+ process.title.set(title)
+ process.description.set(description)
+ process.effort.set(effort)
+ process.set_conditions(self.conn, conditions)
+ process.set_blockers(self.conn, blockers)
+ process.set_enables(self.conn, enables)
+ process.set_disables(self.conn, disables)
+ process.calendarize = calendarize
+ process.save(self.conn)
+ assert isinstance(process.id_, int)
+ new_step_title = None
+ steps: list[ProcessStep] = []
+ for step_id in keep_steps:
+ if step_id not in step_ids:
+ raise BadFormatException('trying to keep unknown step')
+ step = ProcessStep(step_id, process.id_,
+ step_process_id_to[step_id],
+ step_parent_id_to[step_id])
+ steps += [step]
+ 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:
+ try:
+ step_process_id = int(step_identifier)
+ step = ProcessStep(None, process.id_, step_process_id, None)
+ steps += [step]
+ except ValueError:
+ new_step_title = step_identifier
+ process.set_steps(self.conn, steps)
+ process.set_step_suppressions(self.conn, suppresses)
+ owners_to_set = []
+ new_owner_title = None
+ for owner_identifier in step_of:
+ try:
+ owners_to_set += [int(owner_identifier)]
+ except ValueError:
+ new_owner_title = owner_identifier
+ process.set_owners(self.conn, owners_to_set)
+ params = f'id={process.id_}'
+ if new_step_title:
+ title_b64_encoded = b64encode(new_step_title.encode()).decode()
+ params = f'step_to={process.id_}&title_b64={title_b64_encoded}'
+ elif new_owner_title:
+ title_b64_encoded = b64encode(new_owner_title.encode()).decode()
+ params = f'has_step={process.id_}&title_b64={title_b64_encoded}'
+ process.save(self.conn)
+ return f'/process?{params}'
+
+ def do_POST_condition_descriptions(self) -> str:
+ """Update history timestamps for Condition.description."""
+ return self._change_versioned_timestamps(Condition, 'description')
+
+ def do_POST_condition_titles(self) -> str:
+ """Update history timestamps for Condition.title."""
+ return self._change_versioned_timestamps(Condition, 'title')
+
+ @_delete_or_post(Condition, '/conditions')
+ def do_POST_condition(self, condition: Condition) -> str:
+ """Update/insert Condition of ?id= and fields defined in postvars."""
+ is_active = self._form_data.get_str('is_active') == 'True'
+ title = self._form_data.get_str('title')
+ description = self._form_data.get_str('description')
+ condition.is_active = is_active
+ condition.title.set(title)
+ condition.description.set(description)
+ condition.save(self.conn)
+ return f'/condition?id={condition.id_}'