def update_athlete(request, id): if id: data = { 'title': "Alterar atleta", 'title_h': "Atualização", 'athlete': Athlete.get_by_id(id), 'team': Country.list_all(), 'sport': Sport.list_all(), } return render(request, 'athlete/create.html', data)
def add_participation(request, id): if id: athlete = Athlete.get_by_id(id) participants = EventParticipants.filter_by_athlete(athlete) games_events = GameEvent.get_did_not_participate(participants) data = { 'title': "Adicionar participacao em evento", 'athlete': athlete, 'games_events': games_events } return render(request, 'athlete/participation.html', data) return redirect("/athlete/filter/")
def participation_athlete_submit(request): if request.POST and request.POST.get("id"): id = request.POST.get("id") age = request.POST.get("age") game_event_id = request.POST.get("game_event_id") medal_id = request.POST.get("medal_id") if age != "": athlete = Athlete.get_by_id(id) game_event = GameEvent.get_by_id(game_event_id) medal = Medal.get_by_id(medal_id) EventParticipants.create(athlete, age, game_event, medal) return redirect("/athlete/view/?id={}".format(id)) else: messages.error(request, "* Idade não pode estar vazia") return redirect("/athlete/filter/")
def save_event_participants(athlete, request): athlete[['Name', 'Sex', 'Medal']].fillna(value="", inplace=True) athlete['Height'].fillna(value=athlete['Height'].mean(), inplace=True) athlete['Weight'].fillna(value=athlete['Weight'].mean(), inplace=True) athlete['Age'].fillna(value=athlete['Age'].mean(), inplace=True) athlete.sort_values("Name", inplace=True) registered_country = Country.get_registered_regions() registered_sport = Sport.get_registered_sports() registered_athlete = Athlete.get_registered_athlete() registered_season = Season.get_registered_season() registered_city = City.get_registered_city() registered_events = Event.get_registered_events() registered_games = Game.get_registered_games() registered_game_event = GameEvent.get_registered_games_event() registered_participant = EventParticipants.get_registered_game_event_participant( ) message_except = "Erro ao cadastrar o atleta no evento" for item in athlete.iterrows(): if not region_not_exist(item[1]["NOC"], registered_country): if not sport_not_exist(item[1]["Sport"], registered_sport): season_id = get_in_dataframe(item[1]["Season"], "name", registered_season) city_id = get_in_dataframe(item[1]["City"], "name", registered_city) event_id = get_in_dataframe(item[1]["Event"], "name", registered_events) game_id = get_game_by_data(item[1]["Year"], season_id, city_id, registered_games) if not game_event_not_exist(game_id, event_id, registered_game_event): sport_id = get_in_dataframe(item[1]["Sport"], "name", registered_sport) team_id = get_in_dataframe(item[1]["NOC"], "noc", registered_country) if not athlete_not_exist( item[1]["Name"], item[1]["Sex"], item[1]["Height"], item[1]["Weight"], team_id, sport_id, registered_athlete): athlete_id = get_athlete_id_in_dataframe( item[1]["Name"], item[1]["Sex"], item[1]["Height"], item[1]["Weight"], team_id, sport_id, registered_athlete) game_event_id = get_game_event_in_dataframe( game_id, event_id, registered_game_event) if event_participant_not_exist(athlete_id, item[1]["Age"], game_event_id, registered_participant): try: game_event = GameEvent.get_game_event_by_id( game_event_id) athlete = Athlete.get_by_id(athlete_id) medal = Medal.get_medal(item[1]["Medal"]) EventParticipants.create( athlete, item[1]["Age"], game_event, medal) registered_participant = update_registered_participant( registered_athlete, athlete_id, item[1]["Age"], game_event_id) except: register_message( item[1]["Name"] + " " + item[1]["Event"], message_except, request)