home · contact · privacy
Also allow creation of new Processes as owner of current Process, with respective...
authorChristian Heller <c.heller@plomlompom.de>
Thu, 6 Jun 2024 03:39:39 +0000 (05:39 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 6 Jun 2024 03:39:39 +0000 (05:39 +0200)
plomtask/http.py
templates/process.html

index 9680778bcdb21cd8526a3db46530e55ee8aa0834..2b630a22376edf6f0a51c10a2de6a4fe4ae20ff6 100644 (file)
@@ -243,9 +243,12 @@ class TaskHandler(BaseHTTPRequestHandler):
         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)]
         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)]
+        preset_top_step = None
+        for process_id in self.params.get_all_int('has_step'):
+            preset_top_step = process_id
         return {'process': process, 'is_new': process.id_ is None,
         return {'process': process, 'is_new': process.id_ is None,
-                'steps': process.get_steps(self.conn),
-                'owners': owners,
+                'preset_top_step': preset_top_step,
+                'steps': process.get_steps(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)}
                 'n_todos': len(Todo.by_process_id(self.conn, process.id_)),
                 'process_candidates': Process.all(self.conn),
                 'condition_candidates': Condition.all(self.conn)}
@@ -370,6 +373,7 @@ class TaskHandler(BaseHTTPRequestHandler):
 
     def do_POST_process(self) -> str:
         """Update or insert Process of ?id= and fields defined in postvars."""
 
     def do_POST_process(self) -> str:
         """Update or insert Process of ?id= and fields defined in postvars."""
+        # pylint: disable=too-many-branches
         id_ = self.params.get_int_or_none('id')
         for _ in self.form_data.get_all_str('delete'):
             process = Process.by_id(self.conn, id_)
         id_ = self.params.get_int_or_none('id')
         for _ in self.form_data.get_all_str('delete'):
             process = Process.by_id(self.conn, id_)
@@ -405,25 +409,35 @@ class TaskHandler(BaseHTTPRequestHandler):
                     f'new_step_to_{step_id}'):
                 steps += [ProcessStep(None, process.id_, step_process_id,
                                       step_id)]
                     f'new_step_to_{step_id}'):
                 steps += [ProcessStep(None, process.id_, step_process_id,
                                       step_id)]
-        new_process_title = None
+        new_step_title = None
         for step_identifier in self.form_data.get_all_str('new_top_step'):
             try:
                 step_process_id = int(step_identifier)
                 steps += [ProcessStep(None, process.id_, step_process_id,
                                       None)]
             except ValueError:
         for step_identifier in self.form_data.get_all_str('new_top_step'):
             try:
                 step_process_id = int(step_identifier)
                 steps += [ProcessStep(None, process.id_, step_process_id,
                                       None)]
             except ValueError:
-                new_process_title = step_identifier
+                new_step_title = step_identifier
         process.uncache()
         process.set_steps(self.conn, steps)
         process.set_step_suppressions(self.conn,
                                       self.form_data.get_all_int('suppresses'))
         process.save(self.conn)
         process.uncache()
         process.set_steps(self.conn, steps)
         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()
+        owners_to_set = []
+        new_owner_title = None
+        for owner_identifier in self.form_data.get_all_str('step_of'):
+            try:
+                owners_to_set += [int(owner_identifier)]
+            except ValueError:
+                new_owner_title = owner_identifier
+        process.set_owners(self.conn, owners_to_set)
+        params = f'id={process.id_}'
+        if new_step_title:
+            title_b64_encoded = b64encode(new_step_title.encode()).decode()
             params = f'step_to={process.id_}&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_}'
+        elif new_owner_title:
+            title_b64_encoded = b64encode(new_owner_title.encode()).decode()
+            params = f'has_step={process.id_}&title_b64={title_b64_encoded}'
+        return f'/process?{params}'
 
     def do_POST_condition(self) -> str:
         """Update/insert Condition of ?id= and fields defined in postvars."""
 
     def do_POST_condition(self) -> str:
         """Update/insert Condition of ?id= and fields defined in postvars."""
index 8239dc27ef41104dd1ab701a3ca2556c31c7753e..1be3daf344d1621ff58990ed5fc38a81d0b723b6 100644 (file)
@@ -92,7 +92,7 @@ add sub-step: <input name="new_step_to_{{step_id}}" list="process_candidates" au
 {{ step_with_steps(step_id, step_node, 0) }}
 {% endfor %}
 </table>
 {{ step_with_steps(step_id, step_node, 0) }}
 {% endfor %}
 </table>
-add: <input name="new_top_step" list="process_candidates" autocomplete="off" />
+add: <input name="new_top_step" list="process_candidates" autocomplete="off" value="{{preset_top_step or ''}}" />
 </td>
 </tr>
 
 </td>
 </tr>