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" in dataObject:
			try:
				GM = QRzarGameMapper()

				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.")

				game.setName(dataObject["name"])

				return self._response(Depth.build(game, self.depth), 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" in dataObject:	
			GM = QRzarGameMapper()

			game = QRzarGame()

			game.setName(dataObject["name"])

			if "start_time" in dataObject:
				#Format 2012-11-07 12:53:51
				game.setStartTime(datetime.strptime(dataObject["start_time"], "%Y-%m-%d %H:%M:%S"))

			if "end_time" in dataObject:
				game.setEndTime(datetime.strptime(dataObject["end_time"], "%Y-%m-%d %H:%M:%S"))

			game.setCreator(self.user)

			try:
				GM.insert(game)			
			except mdb.DatabaseError, e:
				raise ServerError("Unable to create the game in the database (%s)" % e.args[1])

			return self._response(Depth.build(game, self.depth), CODE.CREATED)
def main():
	from Networking.protocolhandler import ProtocolHandler
	from Common.config import TopHatConfig

	#setup the config
	TopHatConfig(path="/home/specialk/Dev/tophat/config.py")

	from Model.Mapper.qrzargamemapper import QRzarGameMapper
	from Model.Mapper.usermapper import UserMapper

	# get
	UM = UserMapper()
	user = UM.find(1)

	GM = QRzarGameMapper()
	game = GM.find(1)

	# build
	from Model.depth import Depth
	import pprint

	dic = Depth.build(user, 3)
	pprint.pprint(dic)

	print ""
	print "***********************************************"
	print ""

	dic = Depth.build(game, 3)
	pprint.pprint(dic)
	def _doDelete(self):
		if self.arg is None:
			raise BadRequest("You must provide the ID of the game to be deleted")
		GM = QRzarGameMapper()

		# get the user if it exists
		try:
			if self.arg.isdigit():
				# Get the user by ID
				game = GM.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])
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.qrzargamemapper import QRzarGameMapper
    from Model.Mapper.usermapper import UserMapper
    from Model.Mapper.killmapper import KillMapper
    from Model.Mapper.qrzarplayermapper import QRzarPlayerMapper
    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

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

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

    for kill_ in kills:
        print kill_

    PM = QRzarPlayerMapper()
    players = PM.findAll()

    for player_ in players:
        print player_

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

    usr1 = UM.find(1)
	def _doGet(self):
		try:
			
			GM = QRzarGameMapper()
			
			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(Depth.build(game, self.depth), 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(Depth.build(game, self.depth))

				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])