From: Christian Heller Date: Thu, 6 Jun 2024 02:39:12 +0000 (+0200) Subject: Allow (de-)selection of owners in Process edit view. X-Git-Url: https://plomlompom.com/repos/condition_titles?a=commitdiff_plain;h=23bf47fbbc14ccaf36fc5183720b413eea892ddf;p=plomtask Allow (de-)selection of owners in Process edit view. --- diff --git a/plomtask/http.py b/plomtask/http.py index 2d5db82..9bb96f9 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -244,7 +244,7 @@ class TaskHandler(BaseHTTPRequestHandler): '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]: @@ -415,6 +415,7 @@ class TaskHandler(BaseHTTPRequestHandler): 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}' diff --git a/plomtask/processes.py b/plomtask/processes.py index 6222046..23da7c1 100644 --- a/plomtask/processes.py +++ b/plomtask/processes.py @@ -163,6 +163,27 @@ class Process(BaseModel[int], ConditionsRelations): 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) diff --git a/templates/process.html b/templates/process.html index f073a57..8239dc2 100644 --- a/templates/process.html +++ b/templates/process.html @@ -24,7 +24,7 @@ {% if step_node.is_explicit %} -add sub-step: +add sub-step: {% elif not step_node.seen %} suppress {% endif %} @@ -92,17 +92,13 @@ add sub-step: -add: +add: step of - -{% for owner in owners %} -{{owner.title.newest|e}}
-{% endfor %} - +{{ macros.simple_checkbox_table("step_of", owners, "process", "process_candidates") }} @@ -117,5 +113,5 @@ add: {{ 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 %} diff --git a/tests/todos.py b/tests/todos.py index c45171a..b28ebd8 100644 --- a/tests/todos.py +++ b/tests/todos.py @@ -362,10 +362,12 @@ class TestsWithServer(TestCaseWithServer): 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)