"""Update Todo and its children."""
# pylint: disable=too-many-locals
# pylint: disable=too-many-branches
- # pylint: disable=too-many-statements
adopted_child_ids = self._form_data.get_all_int('adopt')
processes_to_make_full = self._form_data.get_all_int('make_full')
processes_to_make_empty = self._form_data.get_all_int('make_empty')
step_fillers = self._form_data.get_all_str('step_filler')
- with_effort_post = True
+ d: dict[str, str | float | None] = {}
try:
- effort = self._form_data.get_float_or_none('effort')
+ d['effort'] = self._form_data.get_float_or_none('effort')
except NotFoundException:
- with_effort_post = False
- conditions = self._form_data.get_all_int('conditions')
- disables = self._form_data.get_all_int('disables')
- blockers = self._form_data.get_all_int('blockers')
- enables = self._form_data.get_all_int('enables')
- is_done = len(self._form_data.get_all_str('done')) > 0
- calendarize = len(self._form_data.get_all_str('calendarize')) > 0
- comment = self._form_data.get_str('comment', ignore_strict=True)
+ pass
+ cond_rel_id_lists = [self._form_data.get_all_int(name) for name in
+ ['conditions', 'blockers', 'enables', 'disables']]
+ d['is_done'] = len(self._form_data.get_all_str('done')) > 0
+ d['calendarize'] = len(self._form_data.get_all_str('calendarize')) > 0
+ d['comment'] = self._form_data.get_str('comment', ignore_strict=True)
for filler in [f for f in step_fillers if f != 'ignore']:
target_id: int
to_int = filler
for process_id in processes_to_make_full:
made = Todo.create_with_children(self.conn, process_id, todo.date)
todo.add_child(made)
- if with_effort_post:
- todo.effort = effort
- todo.set_condition_relations(
- self.conn, conditions, blockers, enables, disables)
- todo.is_done = is_done
- todo.calendarize = calendarize
- todo.comment = comment
+ todo.set_condition_relations(self.conn, *cond_rel_id_lists)
+ todo.update_attrs(**d)
# todo.save() may destroy Todo if .effort < 0, so retrieve .id_ early
url = f'/todo?id={todo.id_}'
todo.save(self.conn)
self.children.remove(child)
child.parents.remove(self)
+ def update_attrs(self, **kwargs: Any) -> None:
+ """Update self's attributes listed in kwargs."""
+ for k, v in kwargs.items():
+ setattr(self, k, v)
+
def save(self, db_conn: DatabaseConnection) -> None:
"""On save calls, also check if auto-deletion by effort < 0."""
if self.effort and self.effort < 0 and self.is_deletable: