Example #1
0
 def get(self, request, player_id=None):
     if player_id==None:
         data = [model_to_dict(i) for i in Player.get_all()]
         return HttpResponse(json.dumps(data))
     player = Player.get_by_id(player_id)
     player = model_to_dict(player)
     return HttpResponse(json.dumps({"player": player}))
Example #2
0
def get_player(player_id):
    player = Player.get_by_id(player_id)
    game_players = GamePlayer.all().filter('player =', player)
    games = [game_player.game for game_player in game_players]
    info = {}
    for game in games:
        info[str(game.key().id())] = to_dict(game)
    return jsonify(**info)
Example #3
0
 def post(self):
     if login.isAdmin():
         id = long(self.request.get('id'))
         player = Player.get_by_id(id)
         if player.isStarred:
             player.isStarred = False
         else:
             player.isStarred = True
         player.put()
Example #4
0
	def get(self, playerId):		
		player = Player.get_by_id(int(playerId))
		if player:
			values = {"player":player}
			path = os.path.join(os.path.dirname(__file__), 'templates/edit_player.html')			
		else:
			values = { "message" : "Error finding player."}
			path = os.path.join(os.path.dirname(__file__), 'templates/success.html')
		self.response.out.write(template.render(path, values))
Example #5
0
 def post(self):
     if login.isAdmin():
         id = long(self.request.get('id'))
         attribute = self.request.get('attribute')
         value = self.request.get('value')
         player = Player.get_by_id(id)
         if attribute == 'name':
             player.name = value
         elif attribute == 'email':
             player.email = value
         player.put()
def get_player_from_email(email):
  """Helper method to get the Player object corresponding to the given User.
  Creates a new Player object if one didn't exist already.
  """
  email = email.lower()
  player = Player.get_by_id(email, parent=get_parent_key_from_email(email))
  logging.info("player = " + str(player)) 
  if not player:
    logging.info("Failed to find player by id, creating new user")
    player = Player(parent=get_parent_key_from_email(email), id=email)
    player.put()
  return player
Example #7
0
    def put(self, id):
        isActive = Configuration.all().filter('name', 'checkin').get()
        isAdmin = login.isAdmin()
        isPlayer = login.isPlayer() and not isAdmin
        user = users.get_current_user()
        if not isAdmin and not isPlayer:
            self.response.out.write('not_logged_in')
        else:
            request = json.loads(self.request.body)
            status = request['status']
            n_presents = Player.all().filter('status =', 'present').count()

            if status != 'present' or n_presents < 10:
                player = None
                if isAdmin:
                    id = long(id)
                    player = Player.get_by_id(id)
                    logging.info('Admin set status to \'' + status + '\' for ' +
                                 str(player.email))
                elif isPlayer and (isActive is None or isActive.value):
                    player = Player.all()
                    player = player.filter('email =', user.email()).get()
                    logging.info(str(player.email) + ' set status to \'' +
                                 status + '\'')

                if player:
                    player.status = status
                    player.put()
                    #self.response.out.write('ok')
                else:
                    logging.info(user.nickname() + ' (' + user.email() +
                                 ') tried to set status to \'' +
                                 status + '\' but it was inactive')
                    self.response.set_status(401, 'La lista &egrave; bloccata o \
                            non sei pi&ugrave; loggato')

            else:
                logging.info(user.nickname() + ' (' + user.email() +
                             ') tried to set status to \'' + status +
                             '\' but it was full')
                self.response.set_status(500, 'La lista &egrave; piena')
Example #8
0
    def delete(self):
        if login.isAdmin():

            #logging.info(self.request.body)
            #try:
                #player_data = json.loads(self.request.body)
            #except ValueError:
            player_data = self.request
            logging.info(player_data)

            if player_data and player_data.get('id'):
                id = int(player_data.get('id'))
                db_player = Player.get_by_id(id)
                if db_player:
                    db_player.delete()
                    result = playerToJSON(db_player, True)
                    self.response.out.write(result)
                    #send message to clients
                    sendMessage(result)
                else:
                    self.response.out.write('player not found')
Example #9
0
    def post(self):
        request_data = json.loads(self.request.body)
        logging.info(request_data)
        player = current_user_player()
        kicked_player = Player.get_by_id(request_data['player_id'])
        team = kicked_player.team.get()

        # VALIDATIONS
        if not validate_is_team_owner(self.response, player, team):
            return
        if player == kicked_player:
            error_400(self.response, "ERROR_CANT_KICK_SELF", "You cannot kick yourself from your own team. Are you retarded?")
            return

        # DO SHIT
        kicked_player.team = None
        kicked_player.put()

        websocket_notify_player("Player_KickedFromTeam", kicked_player.key, "player", {'team': None})
        _websocket_notify_team("Team_KickedMember", team.key, "player.team.members.-[%s]" % kicked_player.key.id(), kicked_player.get_data_nick_and_id())
        set_json_response(self.response, {'code': "OK"})
Example #10
0
    def post(self):
        #email = users.get_current_user().email()
        isActive = Configuration.all().filter('name', 'checkin').get()
        isAdmin = login.isAdmin()
        isPlayer = login.isPlayer() and not isAdmin
        user = users.get_current_user()
        if not isAdmin and not isPlayer:
            self.response.out.write('not_logged_in')
        else:
            n_presents = Player.all().filter('status =', 'present').count()
            status = self.request.get('status')
            if status != 'present' or n_presents < 10:
                player = None
                id = self.request.get('id')
                if isAdmin and id:
                    id = long(id)
                    player = Player.get_by_id(id)
                    logging.info('Admin set status to \'' + 
                            status + '\' for ' + str(player.email))
                elif isActive == None or isActive.value:
                    player = Player.all()
                    player = player.filter('email =', user.email()).get()
                    logging.info(str(player.email) + ' set status to \'' + 
                            status + '\'')

                if player:
                    player.status = status
                    player.put()
                    self.response.out.write('ok')
                else:
                    logging.info(user.nickname() + ' (' + user.email() + 
                            ') tried to set status to \'' + status + 
                            '\' but it was inactive')
                    self.response.out.write('inactive')

            else:
                logging.info(user.nickname() + ' (' + user.email() + 
                        ') tried to set status to \'' + status + 
                        '\' but it was full')
                self.response.out.write('full')
Example #11
0
    def post(self):
        request_data = json.loads(self.request.body)
        player = current_user_player()
        team = player.team.get()

        # VALIDATIONS
        if not validate_request_data(self.response, request_data, ['ranked_start_hour', 'ranked_end_hour', 'members_role']):
            return
        if not validate_is_team_owner(self.response, player, team):
            return

        # DO SHIT
        team.ranked_start_hour = int(request_data['ranked_start_hour'])
        team.ranked_end_hour = int(request_data['ranked_end_hour'])
        team.put()

        for member_role in request_data['members_role']:
            member = Player.get_by_id(member_role['id'])
            member.team_role = member_role['role']
            member.put()

        set_json_response(self.response, {'code': "OK"})
Example #12
0
	def post(self, playerId):
		deleteClicked = self.request.get("delete")
		player = Player.get_by_id(int(playerId))
		if player:
			if deleteClicked:
				player.delete()
				values = { "message" : "Player deleted successfully."}
			else:	
				#TODO: optimize this... if values are equal, don't post
				player.fname = self.request.get("fname%s" % playerId)
				player.lname = self.request.get("lname%s" % playerId)
				player.email = self.request.get("email%s" % playerId)
				phone = self.request.get("phone%s" % playerId)
				if phone:
					player.phone = phone
				inOrOut = self.request.get("inOrOut")
				if inOrOut == "in":
					player.inThisWeek = True
				else:
					player.inThisWeek = False
				playerType = self.request.get("playerType")
				logging.info(playerType)
				if playerType == "goalie":
					player.goalie = True
				else:
					player.goalie = False
				regularOrSub = self.request.get("regularOrSub")
				if regularOrSub == "sub":
					player.sub = True
				else:
					player.sub = False
				player.put()
				memcache.delete('players')
				values = { "message" : "Changes have been saved successfully."}
		else:
			values = { "message" : "Error finding player."}
		path = os.path.join(os.path.dirname(__file__), 'templates/success.html')
		self.response.out.write(template.render(path, values))
Example #13
0
    def post(self):

        isAdmin = login.isAdmin()
        isPlayer = login.isPlayer()
        user = users.get_current_user()

        if not isAdmin and not isPlayer:
            self.response.set_status(500, message='You must log in')
            self.response.out.write('You must log in')
            return

        # get player data
        logging.info(self.request.body)
        try:
            player_data = json.loads(self.request.body)
        except ValueError:
            player_data = self.request
        logging.info(player_data)

        if player_data and player_data.get('id'):
            id = int(player_data.get('id'))
            db_player = Player.get_by_id(id)
        elif player_data.get('name'):
            db_player = Player(name=player_data['name'])
        else:
            self.response.set_status(500, message='You have not specified an id or a name')
            self.response.out.write('You have not specified an id or a name')
            return

        if not isAdmin and db_player.email != user.email():
            logging.info(db_player.email)
            logging.info(user.email())
            self.response.set_status(500, message='You are not authorized')
            self.response.out.write('You are not authorized')
            return

        # edit player in db
        if db_player:

            status = player_data.get('status') or 'waiting'
            # check if status is valid
            n_presents = Player.all().filter('status =', 'present').count()
            if db_player.status != 'present' and status == 'present' and n_presents >= 10:
                logging.info(user.nickname() + ' (' + user.email() +
                             ') tried to set status to \'' + status +
                             '\' but it was full')
                self.response.set_status(500, message='La lista e\' piena')
                self.response.out.write('La lista e\' piena')
                return

            db_player.status = status

            if isAdmin:
                isStarred = player_data.get('isStarred') == 'True' or False
                db_player.isStarred = isStarred
                db_player.name = player_data.get('name')
                if player_data.get('email'):
                    db_player.email = player_data.get('email')

            db_player.put()

            #send message to clients
            result = playerToJSON(db_player, isAdmin)
            sendMessage(result)
            self.response.out.write(result)

        else:
            self.response.out.write('emptyName')
Example #14
0
 def post(self):
     if login.isAdmin():
         id = long(self.request.get('id'))
         player = Player.get_by_id(id)
         player.delete()
         self.response.out.write(id)
Example #15
0
 def get_record(self, player_id):
   logger.info('NdbplayerDao:: DBHIT: get_record for %s ' % player_id)
   return Player.get_by_id(long(player_id))