Esempio n. 1
0
	def _doPut(self, dataObject):

		if  "id" and ("name" or "photo") in dataObject:
			try:

				PM = PlayerMapper()

				if dataObject["id"] is not None and dataObject["id"].isdigit():
					# Get the user by ID
					player = PM.find(dataObject["id"])

					if player is None:
						raise NotFound("The specified player type does not exist.")
				else:
					raise BadRequest("Argument provided for this player type is invalid.")

				if player.getUser() is self.user or self.user.accessLevel('super_user'):
					if "name" in dataObject:
						player.setName(dataObject["name"])

					if "photo" in dataObject:
						player.setPhoto(dataObject["photo"])

					PM.update(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])
Esempio n. 2
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])
Esempio n. 3
0
	def _doDelete(self):
		if self.arg is None:
			raise BadRequest("You must provide the ID of the player to be deleted")
		
		PM = PlayerMapper()

		# get the user if it exists
		try:
			if self.arg.isdigit():
				# Get the user by ID
				player = PM.find(self.arg)
			else:
				raise BadRequest("Players 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])
Esempio n. 4
0
	def _doGet(self):
		try:
			
			PM = PlayerMapper()
			
			if self.arg is not None:
				if self.arg.isdigit():
					# Get the user by ID
					player = PM.find(self.arg)
				else:
					raise BadRequest("Players must be requested by ID")

				if player is not None:
					return self._response(player.dict(), CODE.OK)
				else:
					raise NotFound("This player does not exist")
			
			else:

				offset = 0
				players = PM.findAll(offset, offset+50)

				if players is None:
					raise NotFound("There are no players on this system.")

				playerslist = []

				for player in players:
					playerslist.append(player.dict())

				playerslist = {"players":playerslist, "pagination_offset":offset, "max_perpage": 50}

				return self._response(playerslist, CODE.OK)

		except mdb.DatabaseError, e:
				raise ServerError("Unable to search the player database (%s: %s)" % e.args[0], e.args[1])