ParamsParser) -> str:
"""Show single Todo of ?id=."""
id_ = params.get_int_or_none('id')
- if id_ is None:
- raise NotFoundException('Todo of ID not found.')
todo = Todo.by_id(conn, id_)
- return self.server.jinja.get_template('todo.html').render(todo=todo)
+ candidates = Todo.by_date(conn, todo.day.date)
+ return self.server.jinja.get_template('todo.html').render(
+ todo=todo, candidates=candidates)
def do_GET_process(self, conn: DatabaseConnection,
params: ParamsParser) -> str:
postvars = parse_qs(self.rfile.read(length).decode(),
keep_blank_values=True, strict_parsing=True)
form_data = PostvarsParser(postvars)
- if site in ('day', 'process'):
+ if site in ('day', 'process', 'todo'):
getattr(self, f'do_POST_{site}')(conn, params, form_data)
conn.commit()
else:
todo = Todo(None, process, False, day)
todo.save(conn)
+ def do_POST_todo(self, conn: DatabaseConnection, params: ParamsParser,
+ form_data: PostvarsParser) -> None:
+ """Update Todo and its children."""
+ id_ = params.get_int_or_none('id')
+ todo = Todo.by_id(conn, id_)
+ child_id = form_data.get_int_or_none('adopt')
+ if child_id is not None:
+ child = Todo.by_id(conn, child_id)
+ todo.add_child(child)
+ if len(form_data.get_all_str('done')) > 0:
+ if not todo.is_doable:
+ raise BadFormatException('cannot set undoable Todo to done')
+ todo.is_done = True
+ else:
+ todo.is_done = False
+ todo.save(conn)
+
def do_POST_process(self, conn: DatabaseConnection, params: ParamsParser,
form_data: PostvarsParser) -> None:
"""Update or insert Process of ?id= and fields defined in postvars."""