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)
Example #2
0
    def _doPost(self, dataObject):

        if (
            "name" in dataObject
            and "game" in dataObject
            and "respawn_code" in dataObject
            and "reference_code" in dataObject
        ):
            TM = TeamMapper()

            team = Team()

            try:
                game = GameMapper().find(dataObject["game"]["id"])

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

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

            team.setName(dataObject["name"])
            team.setRespawnCode(dataObject["respawn_code"])
            team.setReferenceCode(dataObject["reference_code"])

            try:
                TM.insert(team)
            except mdb.DatabaseError, e:
                raise ServerError("Unable to create the team in the database (%s)" % e.args[1])
	def getTeams(self):
		# check have we gotten the list already
		if self._teams is None:
			from Model.Mapper.teammapper import TeamMapper
			TM = TeamMapper()
			self._teams = TM.getByGame(self)

		return self._teams
	def _doGet(self):	
		TM = TeamMapper()
		
		if self.arg is not None and self.arg.isdigit():
			try:
				# Get the team by ID
				team = TM.find(self.arg)

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

			if team is None:
				raise NotFound("This team does not exist")

			rdata = {
				"score": team.getScore()
			}

			return self._response(rdata, CODE.OK)
Example #5
0
    def _doGet(self):
        try:

            TM = TeamMapper()

            if self.arg is not None:
                if self.arg.isdigit():
                    # Get the user by ID
                    team = TM.find(self.arg)
                else:
                    raise BadRequest("Teams must be requested by ID")

                if team is not None:
                    return self._response(Depth.build(team, self.depth), CODE.OK)
                else:
                    raise NotFound("There is no team identified by the number %s" % self.arg)

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