Ejemplo n.º 1
0
    def _doCreateObject(self, data):
        """Builds the game object given the draw data returned from the database query"""
        from Model.game import Game

        game_ = Game(data["id"])

        # get creator User object
        umapper = UserMapper()
        game_.setCreator(umapper.find(data["creator"]))
        #query = "SELECT * FROM users WHERE id = %s"
        #params = (data["creator"],)
        #creator = DeferredUser(data["creator"], UserMapper, query, params)
        #game_.setCreator(creator)

        # Build the game type information
        gt_data = {}
        gt_data["id"] = data["game_type_id"]
        gt_data["name"] = data["game_type_name"]
        GTM = GameTypeMapper()
        gametype = GTM.createObject(
            gt_data
        )  # advantage is the object is added to the object watcher for future references
        print gametype
        print str(type(gametype))
        game_.setGameType(gametype)

        # set the rest of the information
        game_.setName(data["name"])
        game_.setTime(data["time"])
        game_.setStartTime(data["start_time"])
        game_.setEndTime(data["end_time"])

        return game_
Ejemplo n.º 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])
Ejemplo n.º 3
0
	def _doCreateObject(self, data):
		"""Builds the game object given the draw data returned from the database query"""
		from Model.game import Game
		
		game_ = Game(data["id"])

		# get creator User object
		umapper = UserMapper()
		game_.setCreator(umapper.find(data["creator"]))
		#query = "SELECT * FROM users WHERE id = %s"
		#params = (data["creator"],)
		#creator = DeferredUser(data["creator"], UserMapper, query, params)
		#game_.setCreator(creator)

		# Build the game type information
		gt_data = {}
		gt_data["id"] = data["game_type_id"]
		gt_data["name"] = data["game_type_name"]
		GTM = GameTypeMapper()
		gametype = GTM.createObject(gt_data)		# advantage is the object is added to the object watcher for future references
		print gametype
		print str(type(gametype))
		game_.setGameType(gametype)

		# set the rest of the information
		game_.setName(data["name"])
		game_.setTime(data["time"])
		game_.setStartTime(data["start_time"])
		game_.setEndTime(data["end_time"])

		return game_
Ejemplo n.º 4
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])