Example #1
0
	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])
Example #2
0
	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])
Example #3
0
    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])
Example #4
0
	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])
Example #5
0
    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])
Example #6
0
    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])
Example #7
0
def main():
	from Common.config import TopHatConfig

	#setup the config
	kwargs = {"path":"/home/specialk/Dev/tophat/config.py"}
	TopHatConfig(**kwargs)

	# do the other stuff
	from Model.Mapper.gamemapper import GameMapper
	from Model.Mapper.usermapper import UserMapper
	from Model.Mapper.killmapper import KillMapper
	from Model.Mapper.playermapper import PlayerMapper
	from Model.Mapper.apitokenmapper import ApitokenMapper
	from Model.Mapper.objectwatcher import ObjectWatcher

	# Get All the current Users from the database
	UM = UserMapper()
	users = UM.findAll()
	for usr in users:
		print usr

	KM = KillMapper()
	kills = KM.findAll()

	for kill_ in kills:
		print kill_

	PM = PlayerMapper()
	players = PM.findAll()

	for player_ in players:
		print player_

	GM = GameMapper()
	games = GM.findAll()
	for game_ in games:
		print game_

	ATM = ApitokenMapper()
	tokens = ATM.findAll()
	for token in tokens:
		print token

	usr1 = UM.find(1)
Example #8
0
	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])
Example #9
0
    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])
Example #10
0
	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])
Example #11
0
	def _doPost(self, dataObject):

		if "killer" and "victim" and "time" in dataObject:
			try:
				KM = KillMapper()
				GM = GameMapper()
				PM = PlayerMapper()

				if dataObject["killer"] is not None and dataObject["victim"] is not None:

					if "id" in dataObject["killer"] and "id" in dataObject["victim"]:
						# Get the user by ID
						killer = PM.find(dataObject["killer"]["id"])

						victim = PM.find(dataObject["victim"]["id"])

						try:
							proptime = parseDateTime(dataObject["time"])
						except:
							raise BadRequest("""Invalid Time object sent, acceptable formats: 	Acceptable formats are: "YYYY-MM-DD HH:MM:SS.ssssss+HH:MM",
							"YYYY-MM-DD HH:MM:SS.ssssss",
							"YYYY-MM-DD HH:MM:SS+HH:MM",
							"YYYY-MM-DD HH:MM:SS" """)

						if killer is None or victim is None:
							raise NotFound("Either the victim or the killer were invalid player objects")
					else:
						raise BadRequest("Arguments provided for this kill are invalid.")

				else:
					raise BadRequest("Arguments provided for this kill are invalid.")

				kill = Kill()

				kill.setKiller(killer)
				kill.setVictim(victim)
				kill.setVerified(False)

				kill.setTime(proptime)

				KM.insert(kill)

				return self._response(kill.dict(3), CODE.CREATED)
				
			except mdb.DatabaseError, e:
				raise ServerError("Unable to search the user database (%s)" % e.args[1])
Example #12
0
	def loadGames(self):
		from Model.Mapper.gamemapper import GameMapper
		GM = GameMapper()
		self._games = GM.findByUser(self)