當前位置: 首頁>>代碼示例>>Python>>正文


Python User.board_subscribed方法代碼示例

本文整理匯總了Python中server.models.User.board_subscribed方法的典型用法代碼示例。如果您正苦於以下問題:Python User.board_subscribed方法的具體用法?Python User.board_subscribed怎麽用?Python User.board_subscribed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在server.models.User的用法示例。


在下文中一共展示了User.board_subscribed方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: board_routine

# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import board_subscribed [as 別名]
def board_routine(user: User, func, id: int, *args, **kwargs):
    """
    Basic board routine.
    Serves as a layer of abstraction to treat priority errors in board method resource routines.

    This fuction needs to be passed (and called) by session_oriented_request() (inherited from AuthEntity),
    with subroutine function (that has to be called from within this routine) and an ID (serves as Board ID).

    Function passed to this routine needs this signature:
        >>> def func(user: User, board: Board, *args, **kwargs)

    N.B. *args and **kwargs can be omitted.

    :param user:   User Object (got from session_oriented_request())
    :param func:   Subroutine function (needs to be called from within this routine)
    :param id:     Board ID
    :param args:   Name arguments
    :param kwargs: Positional arguments
    :return:
    """
    # Requesting board object
    board = BoardAPI.get_board(id)

    if board is None:
        # Board does not exists
        return responses.client_error(404, 'Board does not exist')
    elif not user.board_subscribed(id):
        # User not subscribed to this board
        return responses.client_error(401, 'User is not authorized to see this board')

    # Return the result got from closure function passed as argument
    return func(user, board, *args, **kwargs)
開發者ID:ar3s3ru,項目名稱:uChan3,代碼行數:34,代碼來源:board.py

示例2: thread_routine

# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import board_subscribed [as 別名]
def thread_routine(user: User, func, id: int, *args, **kwargs):
    """
    Basic thread routine.
    Serves as a layer of abstraction to thread priority errors in thread method resource routines.

    This function needs to be passed (and called) by session_oriented_request() (inherited from AuthEntity),
    with subroutine function (that has to be called from within this routine) and an ID (serves as Thread ID).

    Function passed to this routine needs this signature:
        >>> def func(user: User, thread: Thread, *args, **kwargs)

    N.B. *args and **kwargs can be omitted.

    :param user:   User Object (got from session_oriented_request())
    :param func:   Subroutine function (needs to be called from within this routine)
    :param id:     Thread ID
    :param args:   Name arguments
    :param kwargs: Positional arguments
    :return:
    """
    thread = ThreadAPI.get_thread(id)

    if thread is None:
        return responses.client_error(404, 'Thread does not exist')

    if not user.board_subscribed(thread.board):
        return responses.client_error(401, 'User is not authorized to see this thread')

    return func(user, thread, *args, **kwargs)
開發者ID:ar3s3ru,項目名稱:uChan3,代碼行數:31,代碼來源:thread.py


注:本文中的server.models.User.board_subscribed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。