コード例 #1
0
ファイル: players.py プロジェクト: waynet/TopHat-Platform
	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])
コード例 #2
0
ファイル: games.py プロジェクト: waynet/TopHat-Platform
    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])
コード例 #3
0
ファイル: games.py プロジェクト: Specialkbyte/TopHat-Platform
	def _doDelete(self):
		if self.arg is None:
			raise BadRequest("You must provide the ID of the game to be deleted")
		GM = GameMapper()

		# get the user if it exists
		try:
			if self.arg.isdigit():
				# Get the user by ID
				game = GameMapper.find(self.arg)
			else:
				raise BadRequest("Games must be requested by ID")

		except mdb.DatabaseError, e:
			raise ServerError("Unable to search the user database (%s: %s)" % e.args[0], e.args[1])
コード例 #4
0
ファイル: games.py プロジェクト: Specialkbyte/TopHat-Platform
	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])
コード例 #5
0
ファイル: games.py プロジェクト: waynet/TopHat-Platform
    def _doGet(self):
        try:

            GM = GameMapper()

            if self.arg is not None:
                if self.arg.isdigit():
                    # Get the user by ID
                    game = GM.find(self.arg)
                elif self.arg == "types":
                    return self._response({}, CODE.UNIMPLEMENTED)
                else:
                    raise BadRequest("Games must be requested by ID")

                if game is not None:
                    return self._response(game.dict(3), CODE.OK)
                else:
                    raise NotFound(
                        "There is no game identified by the number %s" %
                        self.arg)

            else:

                offset = 0
                games = GM.findAll(offset, offset + 50)

                if games is None:
                    raise NotFound("There are no games on this system.")

                gameslist = []

                for game in games:
                    gameslist.append(game.dict(2))

                gamedict = {
                    "games": gameslist,
                    "pagination_offset": offset,
                    "max_perpage": 50
                }

                return self._response(gamedict, CODE.OK)

        except mdb.DatabaseError, e:
            raise ServerError(
                "Unable to search the game database (%s: %s)" % e.args[0],
                e.args[1])
コード例 #6
0
ファイル: games.py プロジェクト: waynet/TopHat-Platform
    def _doDelete(self):
        if self.arg is None:
            raise BadRequest(
                "You must provide the ID of the game to be deleted")
        GM = GameMapper()

        # get the user if it exists
        try:
            if self.arg.isdigit():
                # Get the user by ID
                game = GameMapper.find(self.arg)
            else:
                raise BadRequest("Games must be requested by ID")

        except mdb.DatabaseError, e:
            raise ServerError(
                "Unable to search the user database (%s: %s)" % e.args[0],
                e.args[1])
コード例 #7
0
ファイル: games.py プロジェクト: Specialkbyte/TopHat-Platform
	def _doGet(self):
		try:
			
			GM = GameMapper()
			
			if self.arg is not None:
				if self.arg.isdigit():
					# Get the user by ID
					game = GM.find(self.arg)
				elif self.arg == "types":
					return self._response({}, CODE.UNIMPLEMENTED)
				else:
					raise BadRequest("Games must be requested by ID")

				if game is not None:
					return self._response(game.dict(3), CODE.OK)
				else:
					raise NotFound("There is no game identified by the number %s" % self.arg)
			
			else:

				offset = 0
				games = GM.findAll(offset, offset+50)

				if games is None:
					raise NotFound("There are no games on this system.")

				gameslist = []

				for game in games:
					gameslist.append(game.dict(2))

				gamedict = {"games":gameslist, "pagination_offset":offset, "max_perpage": 50}

				return self._response(gamedict, CODE.OK)

		except mdb.DatabaseError, e:
			raise ServerError("Unable to search the game database (%s: %s)" % e.args[0], e.args[1])