예제 #1
0
def save_athlete(athlete, request):
    df = athlete.drop_duplicates("ID", keep='first')
    df[['Name', 'Sex']].fillna(value=" ", inplace=True)
    df['Height'].fillna(value=df['Height'].mean(), inplace=True)
    df['Weight'].fillna(value=df['Weight'].mean(), inplace=True)

    registered_country = Country.get_registered_regions()
    registered_sport = Sport.get_registered_sports()
    registered_athlete = Athlete.get_registered_athlete()

    message_except = "Erro ao cadastrar o atleta "
    for item in df.iterrows():
        if not region_not_exist(item[1]["NOC"], registered_country):
            if not sport_not_exist(item[1]["Sport"], registered_sport):

                sport_id = get_in_dataframe(item[1]["Sport"], "name",
                                            registered_sport)
                team_id = get_in_dataframe(item[1]["NOC"], "noc",
                                           registered_country)

                if athlete_not_exist(item[1]["Name"], item[1]["Sex"],
                                     item[1]["Height"], item[1]["Weight"],
                                     team_id, sport_id, registered_athlete):
                    try:
                        Athlete.create(item[1]["Name"], item[1]["Height"],
                                       item[1]["Weight"], item[1]["Sex"],
                                       team_id, sport_id)

                        registered_athlete = update_registered_athlete(
                            registered_athlete, item[1]["Name"],
                            item[1]["Sex"], item[1]["Height"],
                            item[1]["Weight"], team_id, sport_id)
                    except:
                        register_message(item[1]["ID"] + " " + item[1]["Name"],
                                         message_except, request)
예제 #2
0
def create_athlete_submit(request):
    if request.POST:
        name = request.POST.get("name")
        height = request.POST.get("height")
        weight = request.POST.get("weight")
        sex = request.POST.get("sex")
        team_id = request.POST.get("team_id")
        sport_id = request.POST.get("sport_id")

        if create_athlete_validate(name, height, weight):
            athlete = Athlete.create(name, height, weight, sex, team_id,
                                     sport_id)

            if athlete is None:
                messages.error(request, "Erro no cadastro")
            else:
                return redirect("/athlete/view/?id={}".format(athlete.id))
        else:
            message_error(name, height, weight, request)

        return redirect('/athlete/create')
    else:
        messages.error(request, "Erro no post")