'steps': process.get_steps(self.conn),
'owners': process.used_as_step_by(self.conn),
'n_todos': len(Todo.by_process_id(self.conn, process.id_)),
- 'step_candidates': Process.all(self.conn),
+ 'process_candidates': Process.all(self.conn),
'condition_candidates': Condition.all(self.conn)}
def do_GET_process_titles(self) -> dict[str, object]:
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()
return f'/process?title_b64={title_b64_encoded}'
walk_steps(step)
self.explicit_steps += [step]
+ def set_owners(self, db_conn: DatabaseConnection,
+ owner_ids: list[int]) -> None:
+ """Re-set owners to those identified in owner_ids."""
+ owners_old = self.used_as_step_by(db_conn)
+ losers = [o for o in owners_old if o.id_ not in owner_ids]
+ owners_old_ids = [o.id_ for o in owners_old]
+ winners = [Process.by_id(db_conn, id_) for id_ in owner_ids
+ if id_ not in owners_old_ids]
+ steps_to_remove = []
+ for loser in losers:
+ steps_to_remove += [s for s in loser.explicit_steps
+ if s.step_process_id == self.id_]
+ for step in steps_to_remove:
+ step.remove(db_conn)
+ for winner in winners:
+ assert isinstance(winner.id_, int)
+ assert isinstance(self.id_, int)
+ new_step = ProcessStep(None, winner.id_, self.id_, None)
+ new_explicit_steps = winner.explicit_steps + [new_step]
+ winner.set_steps(db_conn, new_explicit_steps)
+
def save(self, db_conn: DatabaseConnection) -> None:
"""Add (or re-write) self and connected items to DB."""
super().save(db_conn)
</td>
<td>
{% if step_node.is_explicit %}
-add sub-step: <input name="new_step_to_{{step_id}}" list="step_candidates" autocomplete="off" />
+add sub-step: <input name="new_step_to_{{step_id}}" list="process_candidates" autocomplete="off" />
{% elif not step_node.seen %}
<input type="checkbox" name="suppresses" value="{{step_id}}" {% if step_node.is_suppressed %}checked{% endif %}> suppress
{% endif %}
{{ step_with_steps(step_id, step_node, 0) }}
{% endfor %}
</table>
-add: <input name="new_top_step" list="step_candidates" autocomplete="off" />
+add: <input name="new_top_step" list="process_candidates" autocomplete="off" />
</td>
</tr>
<tr>
<th>step of</th>
-<td>
-{% for owner in owners %}
-<a href="process?id={{owner.id_}}">{{owner.title.newest|e}}</a><br />
-{% endfor %}
-</td>
+<td>{{ macros.simple_checkbox_table("step_of", owners, "process", "process_candidates") }}</td>
</tr>
<tr>
</form>
{{ macros.datalist_of_titles("condition_candidates", condition_candidates) }}
-{{ macros.datalist_of_titles("step_candidates", step_candidates) }}
+{{ macros.datalist_of_titles("process_candidates", process_candidates) }}
{% endblock %}
def check_nesting_adoption(process_id: int, date: str,
new_top_steps: list[int]) -> None:
- form_data = self.post_process()
- form_data = self.post_process(process_id,
- form_data |
- {'new_top_step': new_top_steps})
+ form_data = {'title': '', 'description': '', 'effort': 1,
+ 'step_of': [2]}
+ form_data = self.post_process(1, form_data)
+ form_data['new_top_step'] = new_top_steps
+ form_data['step_of'] = []
+ form_data = self.post_process(process_id, form_data)
form_data = {'day_comment': '', 'new_todo': [process_id]}
self.check_post(form_data, f'/day?date={date}', 302)
day_todos = Todo.by_date(self.db_conn, date)