Пример #1
0
	def _doPost(self, dataObject):
		if "name" and "game" and "qrcode" in dataObject:
			if "id" not in dataObject["game"]:
				raise BadRequest("Argument provided for this game type is invalid.")

			reference_code = dataObject["qrcode"][:1]
			qr_code = dataObject["qrcode"]
			try:
				
				team = TeamMapper().findByGameIdAndCode(dataObject["game"]["id"], reference_code)

				if team is None:
					raise NotFound("The specified game id with the QRcode was not found on the server.")

				if QRzarPlayerMapper().getPlayerByQrcode(team.getGame(),qr_code ) is not None:
					raise Conflict("Your QR code is in use in this game: %s." % qr_code)


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

			if team is None:
				raise NotFound("Unable to find team to add player to. Check your qrcode setup.")

			player = QRzarPlayer()
			player.setName(dataObject["name"])
			player.setQRCode(qr_code)
			player.setUser(self.user)
			team.addPlayer(player)

			QRzarPlayerMapper().insert(player)

			return self._response(Depth.build(player, self.depth), CODE.CREATED)