# pylint: disable=too-many-locals
# pylint: disable=too-many-branches
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')
+ to_make = {'full': self._form_data.get_all_int('make_full'),
+ 'empty': self._form_data.get_all_int('make_empty')}
step_fillers = self._form_data.get_all_str('step_filler')
to_update = {
'is_done': self._form_data.get_bool('done'),
'calendarize': self._form_data.get_bool('calendarize'),
'comment': self._form_data.get_str('comment', ignore_strict=True)}
+ cond_rels = [self._form_data.get_all_int(name) for name in
+ ['conditions', 'blockers', 'enables', 'disables']]
try:
to_update['effort'] = self._form_data.get_float_or_none('effort')
except NotFoundException:
pass
- cond_rel_id_lists = [self._form_data.get_all_int(name) for name in
- ['conditions', 'blockers', 'enables', 'disables']]
+ todo.set_condition_relations(self.conn, *cond_rels)
for filler in [f for f in step_fillers if f != 'ignore']:
target_id: int
to_int = filler
msg = 'bad fill_for target: {filler}'
raise BadFormatException(msg) from e
if filler.startswith('make_empty_'):
- processes_to_make_empty += [target_id]
+ to_make['empty'] += [target_id]
elif filler.startswith('make_full_'):
- processes_to_make_full += [target_id]
+ to_make['full'] += [target_id]
else:
adopted_child_ids += [target_id]
to_remove = []
for child in todo.children:
- assert isinstance(child.id_, int)
- if child.id_ not in adopted_child_ids:
+ if child.id_ and (child.id_ not in adopted_child_ids):
to_remove += [child.id_]
for id_ in to_remove:
child = Todo.by_id(self.conn, id_)
for child_id in adopted_child_ids:
if child_id not in [c.id_ for c in todo.children]:
todo.add_child(Todo.by_id(self.conn, child_id))
- for process_id in processes_to_make_empty:
- process = Process.by_id(self.conn, process_id)
- made = Todo(None, process, False, todo.date)
- made.save(self.conn)
- todo.add_child(made)
- for process_id in processes_to_make_full:
- process = Process.by_id(self.conn, process_id)
- made = Todo(None, process, False, todo.date)
- made.save(self.conn)
- made.ensure_children(self.conn)
- todo.add_child(made)
- todo.set_condition_relations(self.conn, *cond_rel_id_lists)
todo.update_attrs(**to_update)
+ for approach, proc_ids in to_make.items():
+ for process_id in proc_ids:
+ process = Process.by_id(self.conn, process_id)
+ made = Todo(None, process, False, todo.date)
+ made.save(self.conn)
+ if 'full' == approach:
+ made.ensure_children(self.conn)
+ todo.add_child(made)
# todo.save() may destroy Todo if .effort < 0, so retrieve .id_ early
url = f'/todo?id={todo.id_}'
todo.save(self.conn)