msg = f'cannot int form field value: {val}'
raise BadFormatException(msg) from e
+ def get_int_or_none(self, key: str) -> int | None:
+ """Retrieve int value of key from self.postvars, or None."""
+ if key not in self.postvars or \
+ 0 == len(''.join(list(self.postvars[key]))):
+ return None
+ return self.get_int(key)
+
def get_float(self, key: str) -> float:
"""Retrieve float value of key from self.postvars."""
val = self.get_str(key)
return
else:
raise NotFoundException(f'Unknown page: /{site}')
- conn.close()
self._send_html(html)
except HandledException as error:
self._send_msg(error, code=error.http_code)
+ finally:
+ conn.close()
def do_GET_calendar(self, conn: DatabaseConnection,
params: ParamsParser) -> str:
"""Show process of ?id=."""
id_ = params.get_int_or_none('id')
process = Process.by_id(conn, id_, create=True)
+ owners = process.used_as_step_by(conn)
return self.server.jinja.get_template('process.html').render(
- process=process, children=process.children(conn),
- candidates=Process.all(conn))
+ process=process, steps=process.get_steps(conn),
+ owners=owners, candidates=Process.all(conn))
def do_GET_processes(self, conn: DatabaseConnection,
_: ParamsParser) -> str:
else:
msg = f'Page not known as POST target: /{site}'
raise NotFoundException(msg)
- conn.close()
self._redirect('/')
except HandledException as error:
self._send_msg(error, code=error.http_code)
+ finally:
+ conn.close()
def do_POST_day(self, conn: DatabaseConnection, params: ParamsParser,
form_data: PostvarsParser) -> None:
process.title.set(form_data.get_str('title'))
process.description.set(form_data.get_str('description'))
process.effort.set(form_data.get_float('effort'))
- process.child_ids = form_data.get_all_int('children')
- process.save(conn)
+ process.save_without_steps(conn)
+ assert process.id_ is not None # for mypy
+ process.explicit_steps = []
+ for step_id in form_data.get_all_int('steps'):
+ for step_process_id in\
+ form_data.get_all_int(f'new_step_to_{step_id}'):
+ process.add_step(conn, None, step_process_id, step_id)
+ if step_id not in form_data.get_all_int('keep_step'):
+ continue
+ step_process_id = form_data.get_int(f'step_{step_id}_process_id')
+ parent_id = form_data.get_int_or_none(f'step_{step_id}_parent_id')
+ process.add_step(conn, step_id, step_process_id, parent_id)
+ for step_process_id in form_data.get_all_int('new_top_step'):
+ process.add_step(conn, None, step_process_id, None)
+ process.fix_steps(conn)
def _init_handling(self) -> tuple[DatabaseConnection, str, ParamsParser]:
conn = DatabaseConnection(self.server.db)