def _doPost(self, dataObject): if "name" and "game" and "photo" in dataObject: try: GameMapper = GM.GameMapper() if dataObject["game"] is not None and str(dataObject["game"]).isdigit(): # Get the user by ID game = GameMapper.find(str(dataObject["game"])) if game is None: raise NotFound("The specified player type does not exist.") else: raise BadRequest("Argument provided for this player type is invalid.") print "GAME GOOD "+str(game) PlayerMapper = PM.PlayerMapper() player = Player() player.setName(dataObject["name"]) player.setGame(game) player.setPhoto(dataObject["photo"]) player.setUser(self.user) PlayerMapper.insert(player) print "PLAYER GOOD "+str(player) GameMapper.joinGame(self.user, player) return self._response(player.dict(3), CODE.CREATED) except mdb.DatabaseError, e: raise ServerError("Unable to search the user database (%s)" % e.args[1])
def _doCreateObject(self, data): """Builds the kill object using the raw data provided from the database""" from Model.player import Player player_ = Player(data["id"]) gmapper = GameMapper() game_ = gmapper.find(data["game_id"]) # If the game is deleted and the player is still linked, then errors can occur player_.setGame(game_) umapper = UserMapper() user_ = umapper.find(data["user_id"]) if user_ is not None: player_.setUser(user_) player_.setName(data["name"]) player_.setPhoto(data["photo"]) player_.setLat(data["lat"]) player_.setLon(data["lon"]) player_.setScore(data["score"]) player_.setTime(data["time"]) return player_
def _doPost(self, dataObject): if "name" and "game" and "photo" in dataObject: try: GM = GameMapper() if dataObject["game"] is not None and str(dataObject["game"]).isdigit(): # Get the user by ID game = GM.find(str(dataObject["game"])) if game is None: raise NotFound("The specified player type does not exist.") else: raise BadRequest("Argument provided for this player type is invalid.") print "GAME GOOD "+str(game) PM = PlayerMapper() player = Player() player.setName(dataObject["name"]) player.setGame(game) player.setPhoto(dataObject["photo"]) player.setUser(self.user) PM.insert(player) print "PLAYER GOOD "+str(player) return self._response(player.dict(3), CODE.CREATED) except mdb.DatabaseError, e: raise ServerError("Unable to search the user database (%s)" % e.args[1])