Esempio n. 1
0
def update_region_submit(request):
    if request.POST and request.POST.get("id"):
        id = request.POST.get("id")
        noc = request.POST.get("noc")
        name = request.POST.get("name")
        notes = request.POST.get("notes")

        country = Country.get_by_id(id)
        if create_region_validate(noc, name):
            if (country.noc == noc) or (Country.get_region_by_noc(noc)
                                        == None):
                if (country.name == name) or (Country.get_region_by_name(name)
                                              == None):
                    country = Country.update(id, noc, name, notes)

                    if country is None:
                        messages.error(request, "Erro no cadastro")
                    else:
                        return redirect("/region/view/?id={}".format(id))
                else:
                    messages.error(request, "País ja registrado")
            else:
                messages.error(request, "NOC ja registrado")
        else:
            message_error_region(noc, name, request)

        return redirect('/region/update/{}'.format(id))
    else:
        messages.error(request, "Erro no post")

    return redirect('/region/create')
Esempio n. 2
0
def create_region_submit(request):
    if request.POST:
        noc = request.POST.get("noc")
        name = request.POST.get("name")
        notes = request.POST.get("notes")

        if create_region_validate(noc, name):
            if Country.get_region_by_noc(noc) == None:
                if Country.get_region_by_name(name) == None:
                    country = Country.create(noc, name, notes)

                    if country is None:
                        messages.error(request, "Erro no cadastro")
                    else:
                        return redirect("/region/view/?id={}".format(
                            country.id))
                else:
                    messages.error(request, "País ja registrado")
            else:
                messages.error(request, "NOC ja registrado")
        else:
            message_error_region(noc, name, request)

        return redirect('/region/create')
    else:
        messages.error(request, "Erro no post")
Esempio n. 3
0
def update_registered_regions(registered, data):
    if len(registered) == 0:
        return Country.get_registered_regions()
    else:
        df = pd.DataFrame([[0, data["NOC"], data["region"], data["notes"]]],
                          [0], ["id", "noc", "name", "notes"])
        return pd.concat([registered, df])
Esempio n. 4
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)
Esempio n. 5
0
def save_region(regions, request):
    regions.fillna(value="", inplace=True)
    registered_regions = Country.get_registered_regions()

    message_except = "Erro ao salvar região"
    for item in regions.iterrows():
        if region_not_exist(item[1]["NOC"], registered_regions):
            try:
                Country.create(
                    item[1]["NOC"],
                    item[1]["region"],
                    item[1]["notes"],
                )
                registered_regions = update_registered_regions(
                    registered_regions, item[1])
            except:
                register_message(item[1]["NOC"], message_except, request)
Esempio n. 6
0
def update_region(request, id):
    if id:
        data = {
            'title': "Alterar país",
            'title_h': "Atualização",
            'region': Country.get_by_id(id)
        }

    return render(request, 'region/create.html', data)
Esempio n. 7
0
def region_delete(request, id):
    if id:
        if Country.delete(id) is False:
            messages.error(request, "Erro durante a exclusão")
        else:
            return redirect("/region/list/")
    else:
        messages.error(request, "País não encontrado")
    return redirect("/region/view/?id={}".format(id))
Esempio n. 8
0
def create_athlete(request):
    data = {
        'title': "Cadastrar atleta",
        'title_h': "Cadastro",
        'athlete': None,
        'team': Country.list_all(),
        'sport': Sport.list_all(),
    }

    return render(request, 'athlete/create.html', data)
Esempio n. 9
0
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)
Esempio n. 10
0
def update(id, name, height, weight, sex, team_id, sport_id):
    try:
        return models.Athlete.objects.filter(id=id).update(
            name=name,
            sex=sex,
            height=height,
            weight=weight,
            team=Country.get_by_id(team_id),
            sport=Sport.get_by_id(sport_id)
        )
    except:
        return None
Esempio n. 11
0
def athlete_filter(request):
    data = {
        'title': "Filtrar atletas",
        'team': Country.list_all(),
        'game': Game.list_all(),
        'event': Event.list_all(),
        'sport': Sport.list_all(),
        'city': City.list_all(),
        'season': Season.list_all(),
    }

    return render(request, 'athlete/filter.html', data)
Esempio n. 12
0
def region_view(request):
    if request.GET and request.GET.get("id"):
        id = request.GET.get("id")

        region = Country.get_by_id(id)
        if region is None:
            region = []

        data = {'title': "Visualizar região", 'region': region}

        return render(request, 'region/view.html', data)

    return redirect('/region/filter')
Esempio n. 13
0
def region_filter_submit(request):
    if request.POST:
        noc = request.POST.get("noc")
        name = request.POST.get("name")
        note = request.POST.get("note")

        if filter_validate_region(noc, name, note):
            data = {
                'title': "Lista de regioes",
                'regions': Country.filter(noc, name, note)
            }

            return render(request, 'region/list.html', data)
        else:
            messages.error(request, "Nenhum um filtro selecionado")

    return redirect('/region/filter')
Esempio n. 14
0
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)
Esempio n. 15
0
def region_list(request):
    data = {'title': "Lista de países", 'regions': Country.list_all()}

    return render(request, 'region/list.html', data)