home · contact · privacy
Allow string entry to step addition field, opening new Process to edit.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 6 Jun 2024 01:47:19 +0000 (03:47 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 6 Jun 2024 01:47:19 +0000 (03:47 +0200)
plomtask/http.py
tests/processes.py

index f6c5dc71db70fb46abfd4b15aaa2cd8cd656410d..ea1358a00f754e217a4ecb9e469f04607962c082 100644 (file)
@@ -1,5 +1,6 @@
 """Web server stuff."""
 from typing import Any
+from base64 import b64encode, b64decode
 from http.server import BaseHTTPRequestHandler
 from http.server import HTTPServer
 from urllib.parse import urlparse, parse_qs
@@ -235,6 +236,10 @@ class TaskHandler(BaseHTTPRequestHandler):
         """Show Process of ?id=."""
         id_ = self.params.get_int_or_none('id')
         process = Process.by_id(self.conn, id_, create=True)
+        title_64 = self.params.get_str('title_b64')
+        if title_64:
+            title = b64decode(title_64.encode()).decode()
+            process.title.set(title)
         return {'process': process,
                 'steps': process.get_steps(self.conn),
                 'owners': process.used_as_step_by(self.conn),
@@ -397,13 +402,22 @@ class TaskHandler(BaseHTTPRequestHandler):
                     f'new_step_to_{step_id}'):
                 steps += [ProcessStep(None, process.id_, step_process_id,
                                       step_id)]
-        for step_process_id in self.form_data.get_all_int('new_top_step'):
-            steps += [ProcessStep(None, process.id_, step_process_id, None)]
+        new_process_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:
+                new_process_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)
+        if new_process_title:
+            title_b64_encoded = b64encode(new_process_title.encode()).decode()
+            return f'/process?title_b64={title_b64_encoded}'
         return f'/process?id={process.id_}'
 
     def do_POST_condition(self) -> str:
index 7701aa0a64658d61da490669dc6d56cf9f79eb54..e374c3b0fb28f2343e4e3c0fd6fdc8c4b6fed1fb 100644 (file)
@@ -339,10 +339,8 @@ class TestsWithServer(TestCaseWithServer):
         self.assertEqual(retrieved_step.step_process_id, 2)
         self.assertEqual(retrieved_step.owner_id, 1)
         self.assertEqual(retrieved_step.parent_step_id, None)
-        # post nonsensical new_top_step id and otherwise zero'd steps, expect
-        # 400 and preservation of previous state
-        form_data_1['new_top_step'] = ['foo']
-        form_data_1['steps'] = []
+        # post nonsense, expect 400 and preservation of previous state
+        form_data_1['steps'] = ['foo']
         form_data_1['keep_step'] = []
         self.check_post(form_data_1, '/process?id=1', 400, '/process?id=1')
         retrieved_process = Process.by_id(self.db_conn, 1)