def _get_current_comment_id(self) -> int: exception_if_none = ContentNotFoundInTracimRequest( "No comment_id property found in request") exception_if_invalid_id = InvalidCommentId( "comment_id is not a correct integer") return self._get_path_id("comment_id", exception_if_none, exception_if_invalid_id)
def _get_current_comment( self, user: User, workspace: Workspace, content: Content, request: 'TracimRequest' ) -> Content: """ Get current content from request :param user: User who want to check the workspace :param workspace: Workspace of the content :param content: comment is related to this content :param request: pyramid request :return: current content """ comment_id = '' try: if 'comment_id' in request.matchdict: comment_id_str = request.matchdict['content_id'] if not isinstance(comment_id_str, str) or not comment_id_str.isdecimal(): # nopep8 raise InvalidCommentId('comment_id is not a correct integer') # nopep8 comment_id = int(request.matchdict['comment_id']) if not comment_id: raise ContentNotFoundInTracimRequest('No comment_id property found in request') # nopep8 api = ContentApi( current_user=user, session=request.dbsession, show_deleted=True, show_archived=True, config=request.registry.settings['CFG'] ) comment = api.get_one( comment_id, content_type=content_type_list.Comment.slug, workspace=workspace, parent=content, ) except NoResultFound as exc: raise ContentNotFound( 'Comment {} does not exist ' 'or is not visible for this user'.format(comment_id) ) from exc return comment