def delete(self): parser = reqparse.RequestParser() parser.add_argument('team_id', type=int, required=True, help='team_id cannot be null') data = parser.parse_args() team = PlayerTeamModel.find_by_team_id(data['team_id']) picks = PickModel.find_team_picks(data['team_id']) if picks is not None: return { 'message': 'Cannot delete this team. Picks are associated to it still.' }, 500 if team.has_paid: return { 'message': 'Cannot delete team that has been marked as paid. ' }, 500 try: team.delete() except: return { 'message': 'An error occurred while deleting the team' }, 500 return {'message': 'Team deleted'}, 200
def advance_week(cls, league): GameController.update_games() week_num = GameModel.get_max_week() active_teams = PlayerTeamModel.get_active_teams_in_league( league.league_id) losing_nfl_teams = GameController.get_losers_for_week(week_num) deactivated_teams = [] advancing_teams = [] for active_team in active_teams: pick = PickModel.find_pick_by_week_and_team_id( week_num, active_team.team_id) if pick is None: active_team.is_active = False deactivated_teams.append(active_team) else: if pick.nfl_team_name in losing_nfl_teams: active_team.is_active = False deactivated_teams.append(active_team) else: active_team.streak += 1 advancing_teams.append(active_team) active_team.upsert() for team in deactivated_teams: if team.user.receive_notifications: send_email("Sorry, you've been eliminated", Config.MAIL_USERNAME, team.user, team) return { 'deactivated_teams': deactivated_teams, 'advancing_teams': advancing_teams }
def delete(self): data = self.parser.parse_args() team = PlayerTeamModel.find_by_team_id(data['team_id']) if not team: return {'message': 'Team with that team_id cannot be found.'}, 401 team.delete() return {'message': 'team was successfully deleted.'}
def decorated_func(*args, **kwargs): try: request_user_info = auth.verify_id_token(request.headers['auth']) team = PlayerTeamModel.find_by_team_id(kwargs['team_id']) except: return {'message': 'Unable to authenticate'}, 403 if team is None or team.user_id != request_user_info['user_id']: return {'message': 'You are not the owner of this team.'}, 403 return f(*args, **kwargs)
def decorated_func(*args, **kwargs): try: request_user_info = auth.verify_id_token(request.headers['auth']) request_data = request.get_json() if 'team_id' in request_data: team = PlayerTeamModel.find_by_team_id(request_data['team_id']) if team is None: return {'message': 'Team not found'}, 403 if team.user_id != request_user_info['user_id']: return { 'message': 'You are not the owner of this team.' }, 403 except: return {'message': 'Unable to authenticate'}, 403 return f(*args, **kwargs)
def delete(self): data = self.parser.parse_args() team = PlayerTeamModel.find_by_team_id(data['team_id']) if not team: return {'message': 'Team with that team_id cannot be found.'}, 401 picks = PickModel.find_team_picks(data['team_id']) if picks is not None: return { 'message': 'Cannot delete this team. Picks are associated to it still.' }, 500 team.delete() return {'message': 'team was successfully deleted.'}
def put(self): self.parser.add_argument( 'has_paid', type=bool, required=True, help='has_paid cannot be null') self.parser.add_argument( 'is_active', type=bool, required=True, help='is_active cannot be null') data = self.parser.parse_args() team = PlayerTeamModel.find_by_team_id(data['team_id']) if not team: return {'message': 'Team with that team_id cannot be found.'}, 401 team.has_paid = data['has_paid'] team.is_active = data['is_active'] team.upsert() return team.json()
def delete(self): parser = reqparse.RequestParser() parser.add_argument('team_id', type=int, required=True, help='team_id cannot be null') data = parser.parse_args() team = PlayerTeamModel.find_by_team_id(data['team_id']) try: team.delete() except: return { 'message': 'An error occurred while deleting the team' }, 500 return {'message': 'Team deleted'}, 200
def put(self): parser = reqparse.RequestParser() parser.add_argument('user_id', type=str, required=True, help='user_id cannot be null') parser.add_argument('team_name', type=str, required=True, help='team_name cannot be null') parser.add_argument('league_id', required=True, help='league_id cannot be null') parser.add_argument('team_id', type=int, required=False) data = parser.parse_args() team = PlayerTeamModel.find_by_team_id(data['team_id']) if team is None: league = LeagueModel.find_league_by_id(data['league_id']) team = PlayerTeamModel(data['user_id'], data['league_id'], data['team_name']) league_type_name = league.league_type.league_type_name if league_type_name == LeagueTypes.STANDARD.name: return StandardLeagueRegisterController.register(league, team) elif league_type_name == LeagueTypes.FREE.name: user = UserModel.find_by_user_id(data['user_id']) return FreeLeagueRegisterController.register( league, team, user) else: return {'message': 'League type not yet implemented.'}, 402 else: team.team_name = data['team_name'] team.upsert() return team.json(), 201
def get(self, team_id): team = PlayerTeamModel.find_by_team_id(team_id) if team: return team.json(), 200 return {'message': 'Could not find a team with that id.'}, 404
def get(self): teams = PlayerTeamModel.get_all_player_teams() return {'teams': [team.json() for team in teams]}
def get(self, user_id): leagueSet = PlayerTeamModel.get_unique_leagues_for_user(user_id) return { 'user_leagues': [league.json_league_info() for league in leagueSet] }