owners = process.used_as_step_by(self.conn)
for step_id in self.params.get_all_int('step_to'):
owners += [Process.by_id(self.conn, step_id)]
+ preset_top_step = None
+ for process_id in self.params.get_all_int('has_step'):
+ preset_top_step = process_id
return {'process': process, 'is_new': process.id_ is None,
- 'steps': process.get_steps(self.conn),
- 'owners': owners,
+ 'preset_top_step': preset_top_step,
+ 'steps': process.get_steps(self.conn), 'owners': owners,
'n_todos': len(Todo.by_process_id(self.conn, process.id_)),
'process_candidates': Process.all(self.conn),
'condition_candidates': Condition.all(self.conn)}
def do_POST_process(self) -> str:
"""Update or insert Process of ?id= and fields defined in postvars."""
+ # pylint: disable=too-many-branches
id_ = self.params.get_int_or_none('id')
for _ in self.form_data.get_all_str('delete'):
process = Process.by_id(self.conn, id_)
f'new_step_to_{step_id}'):
steps += [ProcessStep(None, process.id_, step_process_id,
step_id)]
- new_process_title = None
+ new_step_title = None
for step_identifier in self.form_data.get_all_str('new_top_step'):
try:
step_process_id = int(step_identifier)
steps += [ProcessStep(None, process.id_, step_process_id,
None)]
except ValueError:
- new_process_title = step_identifier
+ new_step_title = step_identifier
process.uncache()
process.set_steps(self.conn, steps)
process.set_step_suppressions(self.conn,
self.form_data.get_all_int('suppresses'))
process.save(self.conn)
- process.set_owners(self.conn, self.form_data.get_all_int('step_of'))
- if new_process_title:
- title_b64_encoded = b64encode(new_process_title.encode()).decode()
+ owners_to_set = []
+ new_owner_title = None
+ for owner_identifier in self.form_data.get_all_str('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}'
- return f'/process?{params}'
- return f'/process?id={process.id_}'
+ elif new_owner_title:
+ title_b64_encoded = b64encode(new_owner_title.encode()).decode()
+ params = f'has_step={process.id_}&title_b64={title_b64_encoded}'
+ return f'/process?{params}'
def do_POST_condition(self) -> str:
"""Update/insert Condition of ?id= and fields defined in postvars."""