"""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
"""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),
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:
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)