From e3b01fe14d7a3b824b909382671acc4657e98145 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Thu, 6 Jun 2024 05:15:12 +0200
Subject: [PATCH] When opening new Process from ProcessStep add field, pre-set
 as owned by previous Process.

---
 plomtask/http.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/plomtask/http.py b/plomtask/http.py
index 9bb96f9..9680778 100644
--- a/plomtask/http.py
+++ b/plomtask/http.py
@@ -240,9 +240,12 @@ class TaskHandler(BaseHTTPRequestHandler):
         if title_64:
             title = b64decode(title_64.encode()).decode()
             process.title.set(title)
+        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)]
         return {'process': process, 'is_new': process.id_ is None,
                 'steps': process.get_steps(self.conn),
-                'owners': process.used_as_step_by(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)}
@@ -418,7 +421,8 @@ class TaskHandler(BaseHTTPRequestHandler):
         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}'
+            params = f'step_to={process.id_}&title_b64={title_b64_encoded}'
+            return f'/process?{params}'
         return f'/process?id={process.id_}'
 
     def do_POST_condition(self) -> str:
-- 
2.30.2