X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/balance?a=blobdiff_plain;f=plomtask%2Fhttp.py;h=2d5db82ccd2e85e7a56ae13c2e52134592efccd7;hb=4c546e0133670dd10aec890c3cea6329c3a29663;hp=249de3286c946464d98c458118c06517206aafb9;hpb=0c668bad3efe0db132452b63ecfef05320ca9e48;p=plomtask diff --git a/plomtask/http.py b/plomtask/http.py index 249de32..2d5db82 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 @@ -10,7 +11,7 @@ from plomtask.days import Day from plomtask.exceptions import HandledException, BadFormatException, \ NotFoundException from plomtask.db import DatabaseConnection, DatabaseFile -from plomtask.processes import Process +from plomtask.processes import Process, ProcessStep from plomtask.conditions import Condition from plomtask.todos import Todo @@ -213,7 +214,7 @@ class TaskHandler(BaseHTTPRequestHandler): id_ = self.params.get_int_or_none('id') c = Condition.by_id(self.conn, id_, create=True) ps = Process.all(self.conn) - return {'condition': c, + return {'condition': c, 'is_new': c.id_ is None, 'enabled_processes': [p for p in ps if c in p.conditions], 'disabled_processes': [p for p in ps if c in p.blockers], 'enabling_processes': [p for p in ps if c in p.enables], @@ -235,7 +236,11 @@ class TaskHandler(BaseHTTPRequestHandler): """Show Process of ?id=.""" id_ = self.params.get_int_or_none('id') process = Process.by_id(self.conn, id_, create=True) - return {'process': process, + title_64 = self.params.get_str('title_b64') + if title_64: + title = b64decode(title_64.encode()).decode() + process.title.set(title) + return {'process': process, 'is_new': process.id_ is None, 'steps': process.get_steps(self.conn), 'owners': process.used_as_step_by(self.conn), 'n_todos': len(Todo.by_process_id(self.conn, process.id_)), @@ -378,7 +383,8 @@ class TaskHandler(BaseHTTPRequestHandler): process.set_disables(self.conn, self.form_data.get_all_int('disables')) process.calendarize = self.form_data.get_all_str('calendarize') != [] process.save(self.conn) - steps: list[tuple[int | None, int, int | None]] = [] + assert isinstance(process.id_, int) + steps: list[ProcessStep] = [] for step_id in self.form_data.get_all_int('keep_step'): if step_id not in self.form_data.get_all_int('steps'): raise BadFormatException('trying to keep unknown step') @@ -389,16 +395,29 @@ class TaskHandler(BaseHTTPRequestHandler): f'step_{step_id}_process_id') parent_id = self.form_data.get_int_or_none( f'step_{step_id}_parent_id') - steps += [(step_id, step_process_id, parent_id)] + steps += [ProcessStep(step_id, process.id_, step_process_id, + parent_id)] for step_id in self.form_data.get_all_int('steps'): for step_process_id in self.form_data.get_all_int( f'new_step_to_{step_id}'): - steps += [(None, step_process_id, step_id)] - for step_process_id in self.form_data.get_all_int('new_top_step'): - steps += [(None, step_process_id, None)] + steps += [ProcessStep(None, process.id_, step_process_id, + step_id)] + 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: