From: Christian Heller Date: Thu, 6 Jun 2024 01:47:19 +0000 (+0200) Subject: Allow string entry to step addition field, opening new Process to edit. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/todo?a=commitdiff_plain;h=16bc51d279619ed41a18551676709e365a89b54a;p=plomtask Allow string entry to step addition field, opening new Process to edit. --- diff --git a/plomtask/http.py b/plomtask/http.py index f6c5dc7..ea1358a 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -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: diff --git a/tests/processes.py b/tests/processes.py index 7701aa0..e374c3b 100644 --- a/tests/processes.py +++ b/tests/processes.py @@ -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)