コード例 #1
0
ファイル: server.py プロジェクト: supermitch/mech-ai
def list_game_by_username_and_id(username, id):
    """
    Return game results as a dictionary, for given query params.

    Common functionality to list games by username & id. Both can be None.
    """
    if id:
        logging.debug("in here")
        results = [game_repo.find_by_id(id)]
    elif username:
        results = game_repo.find_by_username(username)
    else:
        message = "Tried to list games without username or ID"
        webapp2.abort(404, detail=message)

    results = results if results else []
    return {
        "results": [
            {
                "id": game_model.key.id(),
                "name": game_model.name,
                "players": game_model.players,
                "map_name": game_model.map_name,
                "status": game_model.status,
                "created": game_model.created.isoformat(),
                "transactions": json.loads(game_model.transactions),
            }
            for game_model in results
        ]
    }
コード例 #2
0
ファイル: server.py プロジェクト: supermitch/mech-ai
 def get(self, id):
     game_model = game_repo.find_by_id(id)
     if game_model:
         context = {
             "game": {
                 "id": game_model.key.id(),
                 "name": game_model.name,
                 "players": game_model.players,
                 "map_name": game_model.map_name,
                 "status": game_model.status,
                 "created": game_model.created.isoformat(),
                 "transactions": json.loads(game_model.transactions),
             }
         }
         self.render_template("game.html", **context)
     else:
         error_message = "Could not find game for id <{}>".format(id)
         logging.info(error_message)
         webapp2.abort(404, detail=error_message)