Example #1
0
	def add_and_get_country(country):
		if Country.objects.filter(country = country).count() == 0:
			team = Team()
			team.team_cd = utility.get_team_code_from_name(country)
			team.save()
			new_country = Country()
			new_country.country_cd = team
			new_country.country = country
			new_country.save()
		return Country.objects.get(country = country)
def load_teams_tournament(tournament):
    league_name = tournament.tourn_format.tourn.tourn_name
    season = utility.convert_season_string(tournament.season)
    teams = get_teams_by_league_season(league_name, season)
    teamlist = []
    is_club = True
    if not type(teams) == list: raise Exception('Failed to load team data')
    team_cnt = 0
    for team in teams:
        if not TEAM_ID_KEY in team: continue
        team_id = team[TEAM_ID_KEY]
        team_cnt = team_cnt + 1
        if Team.objects.filter(team_api_id=team_id).count() > 0: continue
        new_team = Team()
        new_team.team_api_id = team_id
        new_team.team_cd = utility.get_team_code_from_name(team[TEAM_NAME_KEY])
        new_team.team_logo = load_logo(team[TEAM_WIKI_KEY])
        new_team.save()
        venue = Venue.add_and_get_venue(team[TEAM_STADIUM_KEY])
        if is_club:
            new_club = Club()
            new_club.club_cd = new_team
            new_club.club_name = team[TEAM_NAME_KEY]
            new_club.country = Country.add_and_get_country(
                team[TEAM_COUNTRY_KEY])
            new_club.home_ground = venue
            new_club.save()
            tourn_teams = TournamentTeam.objects.create(team=new_team,
                                                        tourn=tournament)
    tourn_fmt = tournament.tourn_format
    if tourn_fmt.no_of_teams == 0:
        tourn_fmt.no_of_teams = team_cnt
        tourn_fmt.save()
    elif not tourn_fmt.no_of_teams == team_cnt:
        new_fmt = TournamentFormat()
        new_fmt.tourn = tourn_fmt.tourn
        new_fmt.gw_cycle_day = tourn_fmt.gw_cycle_day
        new_fmt.no_of_teams = team_cnt
        new_fmt.save()
        tournament.tourn_format = new_fmt
        tournament.save()
    # load_players(tournament)
    return tournament
def load_teams_tournament(tournament):
	league_name = tournament.tourn_format.tourn.tourn_name
	season = utility.convert_season_string(tournament.season)
	teams = get_teams_by_league_season(league_name, season)
	teamlist = []
	is_club = True
	if not type(teams) == list: raise Exception('Failed to load team data')
	team_cnt = 0
	for team in teams:
		if not TEAM_ID_KEY in team: continue
		team_id = team[TEAM_ID_KEY]
		team_cnt = team_cnt + 1
		if Team.objects.filter(team_api_id = team_id).count() > 0: continue
		new_team = Team()
		new_team.team_api_id = team_id
		new_team.team_cd = utility.get_team_code_from_name(team[TEAM_NAME_KEY])
		new_team.team_logo = load_logo(team[TEAM_WIKI_KEY])
		new_team.save()
		venue = Venue.add_and_get_venue(team[TEAM_STADIUM_KEY])
		if is_club:
			new_club = Club()
			new_club.club_cd = new_team
			new_club.club_name = team[TEAM_NAME_KEY]
			new_club.country = Country.add_and_get_country(team[TEAM_COUNTRY_KEY])
			new_club.home_ground = venue
			new_club.save()
			tourn_teams = TournamentTeam.objects.create(team=new_team, tourn=tournament)
	tourn_fmt = tournament.tourn_format
	if tourn_fmt.no_of_teams == 0:
		tourn_fmt.no_of_teams = team_cnt
		tourn_fmt.save()
	elif not tourn_fmt.no_of_teams == team_cnt:
		new_fmt = TournamentFormat()
		new_fmt.tourn = tourn_fmt.tourn
		new_fmt.gw_cycle_day = tourn_fmt.gw_cycle_day
		new_fmt.no_of_teams = team_cnt
		new_fmt.save()
		tournament.tourn_format = new_fmt
		tournament.save()
	# load_players(tournament)
	return tournament