示例#1
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])
示例#2
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])