def _doGet(self): try: GTM = GameTypeMapper() if self.arg is not None: if self.arg.isdigit(): # Get the user by ID gametype = GTM.find(self.arg) if gametype is not None: return self._response(gametype.dict(3), CODE.OK) else: raise NotFound("The specified game type does not exist.") else: raise BadRequest("Argument provided for this URL is invalid.") else: offset = 0 games = GTM.findAll(offset, offset+50) if games is None: raise NotFound("There are no game types on this system.") gameslist = [] for game in games: gameslist.append(game.dict()) gamedict = {"gametypes":gameslist, "pagination_offset":offset, "max_perpage": 50} return self._response(gamedict, CODE.OK) except mdb.DatabaseError, e: raise ServerError("Unable to search the gametype database (%s: %s)" % e.args[0], e.args[1])
def _doPost(self, dataObject): # The game creation should have no arguments. if self.arg is not None: return self._response({}, CODE.UNIMPLEMENTED) if "name" and "game_type_id" in dataObject: try: GTM = GameTypeMapper() if dataObject["game_type_id"] is not None and dataObject["game_type_id"].isdigit(): # Get the user by ID gametype = GTM.find(dataObject["game_type_id"]) if gametype is None: raise NotFound("The specified game type does not exist.") else: raise BadRequest("Argument provided for this game type is invalid.") GM = GameMapper() # Get the user by E-mail game = Game() game.setName(dataObject["name"]) game.setCreator(self.user) game.setGameType(gametype) GM.insert(game) return self._response(game.dict(3), CODE.CREATED) except mdb.DatabaseError, e: raise ServerError("Unable to search the user database (%s)" % e.args[1])
def _doPut(self, dataObject): # The game creation should have no arguments. if self.arg is None: raise BadRequest( "An ID must be supplied in order to update a game.") if "name" or "game_type_id" in dataObject: try: GM = GameMapper() if self.arg.isdigit(): # Get the user b ID game = GM.find(self.arg) else: raise BadRequest("Games must be requested by ID") if game is None: raise NotFound( "There is no game identified by the number %s" % self.arg) # check user has the priviledges if not self.user.getId() == game.getCreator().getId( ) and not self.user.accessLevel('super_user'): raise Forbidden( "You do not have sufficient privileges to delete this game." ) if "game_type_id" in dataObject: GTM = GameTypeMapper() if dataObject["game_type_id"] is not None and dataObject[ "game_type_id"].isdigit(): # Get the user by ID gametype = GTM.find(dataObject["game_type_id"]) if gametype is None: raise NotFound( "The specified game type does not exist.") else: game.setGameType(gametype) else: raise BadRequest( "Argument provided for this game type is invalid.") if "name" in dataObject: game.setName(dataObject["name"]) GTM.update(game) return self._response(game.dict(3), CODE.CREATED) except mdb.DatabaseError, e: raise ServerError("Unable to search the user database (%s)" % e.args[1])
def _doPut(self, dataObject): # The game creation should have no arguments. if self.arg is None: raise BadRequest("An ID must be supplied in order to update a game.") if "name" or "game_type_id" in dataObject: try: GM = GameMapper() if self.arg.isdigit(): # Get the user b ID game = GM.find(self.arg) else: raise BadRequest("Games must be requested by ID") if game is None: raise NotFound("There is no game identified by the number %s" % self.arg) # check user has the priviledges if not self.user.getId() == game.getCreator().getId() and not self.user.accessLevel('super_user'): raise Forbidden("You do not have sufficient privileges to delete this game.") if "game_type_id" in dataObject: GTM = GameTypeMapper() if dataObject["game_type_id"] is not None and dataObject["game_type_id"].isdigit(): # Get the user by ID gametype = GTM.find(dataObject["game_type_id"]) if gametype is None: raise NotFound("The specified game type does not exist.") else: game.setGameType(gametype) else: raise BadRequest("Argument provided for this game type is invalid.") if "name" in dataObject: game.setName(dataObject["name"]) GTM.update(game) return self._response(game.dict(3), CODE.CREATED) except mdb.DatabaseError, e: raise ServerError("Unable to search the user database (%s)" % e.args[1])
def _doPost(self, dataObject): # The game creation should have no arguments. if self.arg is not None: return self._response({}, CODE.UNIMPLEMENTED) if "name" and "game_type_id" in dataObject: try: GTM = GameTypeMapper() if dataObject["game_type_id"] is not None and dataObject[ "game_type_id"].isdigit(): # Get the user by ID gametype = GTM.find(dataObject["game_type_id"]) if gametype is None: raise NotFound( "The specified game type does not exist.") else: raise BadRequest( "Argument provided for this game type is invalid.") GM = GameMapper() # Get the user by E-mail game = Game() game.setName(dataObject["name"]) game.setCreator(self.user) game.setGameType(gametype) GM.insert(game) return self._response(game.dict(3), CODE.CREATED) except mdb.DatabaseError, e: raise ServerError("Unable to search the user database (%s)" % e.args[1])