"""Collects what's useful to know for ProcessSteps tree display."""
# pylint: disable=too-few-public-methods
step: ProcessStep
+ process: Process
is_explicit: bool
steps: list[ProcessStepsNode]
seen: bool = False
is_suppressed: bool = False
- _to_dict = ['step', 'is_explicit', 'steps', 'seen', 'is_suppressed']
+ _to_dict = ['step', 'process', 'is_explicit', 'steps', 'seen',
+ 'is_suppressed']
class Process(BaseModel[int], ConditionsRelations):
step_steps = []
if not suppressed:
step_steps = process.get_steps(db_conn, external_owner)
- return ProcessStepsNode(step, is_explicit, step_steps, False,
- suppressed)
+ return ProcessStepsNode(step, process, is_explicit, step_steps,
+ False, suppressed)
def walk_steps(node: ProcessStepsNode) -> None:
node.seen = node.step.id_ in seen_step_ids
adoptables = [t for t in Todo.by_date(db_conn, parent.date)
if (t not in parent.children)
and (t != parent)
- and step_node.step.step_process_id == t.process.id_]
+ and step_node.process.id_ == t.process_id]
satisfier = None
for adoptable in adoptables:
satisfier = adoptable
break
if not satisfier:
- proc = Process.by_id(db_conn, step_node.step.step_process_id)
- satisfier = Todo(None, proc, False, parent.date)
+ satisfier = Todo(None, step_node.process, False, parent.date)
satisfier.save(db_conn)
- sub_step_nodes = sorted(step_node.steps,
- key=lambda s: s.step.step_process_id)
+ sub_step_nodes = sorted(
+ step_node.steps,
+ key=lambda s: s.process.id_ if s.process.id_ else 0)
for sub_node in sub_step_nodes:
if sub_node.is_suppressed:
continue
n_slots = len([n for n in sub_step_nodes
- if n.step.step_process_id
- == sub_node.step.step_process_id])
+ if n.process == sub_node.process])
filled_slots = len([t for t in satisfier.children
- if t.process.id_
- == sub_node.step.step_process_id_])
+ if t.process.id_ == sub_node.process.id_])
# if we did not newly create satisfier, it may already fill
# some step dependencies, so only fill what remains open
if n_slots - filled_slots > 0:
@staticmethod
def stepnode_as_dict(step_id: int,
+ proc_id: int,
seen: bool = False,
steps: None | list[dict[str, object]] = None,
is_explicit: bool = True,
is_suppressed: bool = False) -> dict[str, object]:
+ # pylint: disable=too-many-arguments
"""Return JSON of ProcessStepNode to expect."""
return {'step': step_id,
+ 'process': proc_id,
'seen': seen,
'steps': steps if steps else [],
'is_explicit': is_explicit,
# post first (top-level) step of proc 2 to proc 1 by 'step_of' in 2
self.post_exp_process([exp], {'step_of': 1}, 2)
exp.lib_set('ProcessStep', [exp.procstep_as_dict(1, 1, 2)])
- exp.set('steps', [exp.stepnode_as_dict(1)])
+ exp.set('steps', [exp.stepnode_as_dict(1, 2)])
self.check_json_get(url, exp)
# post empty/absent steps list to process, expect clean slate, and old
# step to completely disappear
self.post_exp_process([exp], {'new_top_step': 2}, 1)
exp.lib_set('ProcessStep', [exp.procstep_as_dict(1, 1, 2)])
self.post_exp_process([exp], {'kept_steps': [1]}, 1)
- exp.set('steps', [exp.stepnode_as_dict(1)])
+ exp.set('steps', [exp.stepnode_as_dict(1, 2)])
self.check_json_get(url, exp)
# fail on single- and multi-step recursion
p_min = {'title': '', 'description': '', 'effort': 0}
self.post_exp_process([exp], {'kept_steps': [1], 'new_top_step': 4}, 1)
exp.lib_set('ProcessStep', [exp.procstep_as_dict(1, 1, 4),
exp.procstep_as_dict(2, 1, 4)])
- exp.set('steps', [exp.stepnode_as_dict(1), exp.stepnode_as_dict(2)])
+ exp.set('steps', [exp.stepnode_as_dict(1, 4),
+ exp.stepnode_as_dict(2, 4)])
self.check_json_get(url, exp)
# post sub-step chain
p = {'kept_steps': [1, 2], 'new_step_to_2': 4}
self.post_exp_process([exp], p, 1)
exp.lib_set('ProcessStep', [exp.procstep_as_dict(3, 1, 4, 2)])
- exp.set('steps', [exp.stepnode_as_dict(1),
- exp.stepnode_as_dict(2, steps=[
- exp.stepnode_as_dict(3)])])
+ exp.set('steps', [exp.stepnode_as_dict(1, 4),
+ exp.stepnode_as_dict(2, 4, steps=[
+ exp.stepnode_as_dict(3, 4)])])
self.check_json_get(url, exp)
# fail posting sub-step that would cause recursion
self.post_exp_process([exp], {}, 6)