当前位置: 首页>>代码示例>>Python>>正文


Python User.query方法代码示例

本文整理汇总了Python中models.User.User.query方法的典型用法代码示例。如果您正苦于以下问题:Python User.query方法的具体用法?Python User.query怎么用?Python User.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.User.User的用法示例。


在下文中一共展示了User.query方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: cancel_game

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import query [as 别名]
    def cancel_game(cls, request):
        """
        Removes a game that is currently in progress from the system. The game
        is specificed by Key, contained in the request, and must belong to the currently
        authenticated user.
        """
        # Get the current user - making sure it's authenticated
        gplus_user = get_endpoints_current_user()
        user = User.query(User.email == gplus_user.email()).get()

        # Get the game specified by key in the request
        game = get_by_urlsafe(request.urlsafe_game_key, Game)

        # Ensure the game exists
        if not game:
            raise endpoints.NotFoundException('Game not found!')

        # Ensure the game is associated to the current user
        if user.key != game.user:
            raise endpoints.ForbiddenException("Cannot cancel another user's game!")

        # Ensure the game is not completed
        if game.game_over:
            raise endpoints.ForbiddenException("Cannot cancel a game that has already been completed!")

        # All good to remove the game from datastore
        game.key.delete()
开发者ID:Drew-Kimberly,项目名称:fullstack,代码行数:29,代码来源:GameHandler.py

示例2: user_exists

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import query [as 别名]
def user_exists(username):
    error = {}
    user = User.query(User.username_norm == username.lower()).fetch(1, projection=['username', 'password'])
    if not user:
        error['error_user_exists'] = 'User does not exist'
        return False, error
    return True, user[0]
开发者ID:Ramesh7128,项目名称:udacityplus,代码行数:9,代码来源:errorretrieval.py

示例3: get_user_games

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import query [as 别名]
    def get_user_games(cls):
        """Returns all of the current User's active games"""
        gplus_user = get_endpoints_current_user()
        user = User.query(User.email == gplus_user.email()).get()

        active_games = Game.query() \
            .filter(Game.user == user.key) \
            .filter(Game.game_over == False)
        return GameForms(games=[game.to_form() for game in active_games])
开发者ID:Drew-Kimberly,项目名称:fullstack,代码行数:11,代码来源:GameHandler.py

示例4: get_user_rankings

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import query [as 别名]
    def get_user_rankings(cls, request):
        """
        Returns a list of UserRank forms ordered in descending order
        by total margin of victory.
        """
        # Ensure user is authenticated
        get_endpoints_current_user()

        users = User.query().order(-User.total_victory_margin)
        return UserRankForms(user_ranks=[user.to_rankform() for user in users])
开发者ID:Drew-Kimberly,项目名称:fullstack,代码行数:12,代码来源:UserHandler.py

示例5: get_user_scores

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import query [as 别名]
    def get_user_scores(cls, request):
        """Returns all Scores associated with the current signed-in User"""
        # Check that current user is authenticated
        get_endpoints_current_user()

        user = User.query(User.email == request.email).get()
        if not user:
            raise NotFoundException(
                'A User with that email address does not exist!')

        scores = Score.query(Score.user == user.key)
        return ScoreForms(scores=[score.to_form() for score in scores])
开发者ID:Drew-Kimberly,项目名称:fullstack,代码行数:14,代码来源:ScoreHandler.py

示例6: new_game

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import query [as 别名]
    def new_game(cls, request):
        """Creates and returns a new game"""
        gplus_user = get_endpoints_current_user()
        user = User.query(User.email == gplus_user.email()).get()

        if request.total_rounds not in ROUNDS_OPTIONS:
            raise endpoints.BadRequestException('Invalid total number of rounds.'
                                                ' Must be a number contained in the set: {0}.'.format(ROUNDS_OPTIONS))

        game = Game(user=user.key, total_rounds=request.total_rounds, remaining_rounds=request.total_rounds)
        game.put()
        return game.to_form()
开发者ID:Drew-Kimberly,项目名称:fullstack,代码行数:14,代码来源:GameHandler.py

示例7: valid_email

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import query [as 别名]
def valid_email(email, user=None):
    #TODO: validate email format (regex?)
    e = User.query(User.email == email).get(projection=['username'])

    if e and not user:
        return False, {'error_email': 'Invalid email'}
    elif e and user:
        if e.username == user.username:
            return True, {}
        else:
            return False, {'error_email': 'Invalid email'}
    return True, {}
开发者ID:Ramesh7128,项目名称:udacityplus,代码行数:14,代码来源:errorretrieval.py

示例8: get_game_history

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import query [as 别名]
    def get_game_history(cls, request):
        """
        Returns the round-by-round result of an active or completed Game.
        The game must be associated with the current authenticated user.
        """
        # Get the current user - making sure it's authenticated
        gplus_user = get_endpoints_current_user()
        user = User.query(User.email == gplus_user.email()).get()

        # Get the game specified by key in the request
        game = get_by_urlsafe(request.urlsafe_game_key, Game)

        # Ensure the game exists
        if not game:
            raise endpoints.NotFoundException('Game not found!')

        # Ensure the game is associated to the current user
        if user.key != game.user:
            raise endpoints.ForbiddenException("You may only view the history of your own games!")

        return game.to_gamehistory_form()
开发者ID:Drew-Kimberly,项目名称:fullstack,代码行数:23,代码来源:GameHandler.py


注:本文中的models.User.User.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。