+ @staticmethod
+ def _delete_or_post(target_class: Any, redir_target: str = '/'
+ ) -> Callable[..., Callable[[TaskHandler], str]]:
+ def decorator(f: Callable[..., str]
+ ) -> Callable[[TaskHandler], str]:
+ def wrapper(self: TaskHandler) -> str:
+ # pylint: disable=protected-access
+ # (because pylint here fails to detect the use of wrapper as a
+ # method to self with respective access privileges)
+ id_ = self._params.get_int_or_none('id')
+ for _ in self._form_data.get_all_str('delete'):
+ if id_ is None:
+ msg = 'trying to delete non-saved ' +\
+ f'{target_class.__name__}'
+ raise NotFoundException(msg)
+ item = target_class.by_id(self.conn, id_)
+ item.remove(self.conn)
+ return redir_target
+ if target_class.can_create_by_id:
+ item = target_class.by_id_or_create(self.conn, id_)
+ else:
+ item = target_class.by_id(self.conn, id_)
+ return f(self, item)
+ return wrapper
+ return decorator
+