home · contact · privacy
Allow (de-)selection of owners in Process edit view.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 6 Jun 2024 02:39:12 +0000 (04:39 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 6 Jun 2024 02:39:12 +0000 (04:39 +0200)
plomtask/http.py
plomtask/processes.py
templates/process.html
tests/todos.py

index 2d5db82ccd2e85e7a56ae13c2e52134592efccd7..9bb96f9c3a23aab0e470feba437038796302ffe8 100644 (file)
@@ -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}'
index 62220462936ad9452f45d1f87813bf38fcbb5bab..23da7c10f365539661fbf7cb5815f61158a6c923 100644 (file)
@@ -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)
index f073a5798ed6d0e0a757d4155334f1da7d721e66..8239dc27ef41104dd1ab701a3ca2556c31c7753e 100644 (file)
@@ -24,7 +24,7 @@
 </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 %}
@@ -92,17 +92,13 @@ add sub-step: <input name="new_step_to_{{step_id}}" list="step_candidates" autoc
 {{ 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>
@@ -117,5 +113,5 @@ add: <input name="new_top_step" list="step_candidates" autocomplete="off" />
 </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 %}
index c45171ac9488ed0eda2125c84689b042a85c8763..b28ebd8cdda37c973cf468daa2683140f855dd39 100644 (file)
@@ -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)