Ejemplo n.º 1
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" 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 _doCreateObject(self, data):
		"""Builds the game object given the draw data returned from the database query"""
		from Model.qrzargame import QRzarGame
		from Model.deferredobject import DeferredObject
		from Model.user import User

		game = QRzarGame(data["id"])

		# get creator User object
		creator = DeferredObject(User(data["creator"]))
		game.setCreator(creator)

		# Build the game type information
		game.setName(data["name"])
		game.setTime(data["time"])
		game.setStartTime(data["start_time"])
		game.setEndTime(data["end_time"])

		return game