Exemplo n.º 1
0
def penalties_add_penalty(match_id, team_id):

    form = PenaltyForm(team_id, request.form)

    if not form.validate():
        return render_template("penalties/new.html", form=form)

    start_time = form.start_time.data
    length = form.length.data
    end_time = "20:00"

    sel_reciever_name = str(
        dict(form.reciever_name.choices).get(form.reciever_name.data))
    reciever_id = Player.find_player_id(sel_reciever_name)

    sel_penalty_desc_code = str(
        dict(form.penaltycode.choices).get(form.penaltycode.data))
    sel_penaltycode = (sel_penalty_desc_code[-4:])[:3]
    penalty_id = PenaltyCode.find_penaltycode_id(sel_penaltycode)

    p = Penalty(match_id, team_id, start_time, length, end_time,
                reciever_id[0], penalty_id[0])

    db.session().add(p)
    db.session().commit()

    return redirect(url_for("matches_index"))
Exemplo n.º 2
0
def goals_add_goal(match_id, team_id):

    form = GoalForm(team_id, request.form)

    if not form.validate():
        return render_template("goals/new.html", form=form)

    time = form.time.data

    sel_scorer_name = str(
        dict(form.scorer_name.choices).get(form.scorer_name.data))
    scorer_id = Player.find_player_id(sel_scorer_name)

    sel_assistant_1_name = str(
        dict(form.assistant_1_name.choices).get(form.assistant_1_name.data))
    assistant_1_id = Player.find_player_id(sel_assistant_1_name)

    sel_assistant_2_name = str(
        dict(form.assistant_2_name.choices).get(form.assistant_2_name.data))
    assistant_2_id = Player.find_player_id(sel_assistant_2_name)

    g = Goal(match_id, team_id, time, scorer_id[0], assistant_1_id[0],
             assistant_2_id[0])

    db.session().add(g)
    db.session().commit()

    m = Match.query.get(match_id)
    if str(m.home_team_id) == str(team_id):
        m.home_team_score = m.home_team_score + 1
    else:
        m.away_team_score = m.away_team_score + 1

    db.session().commit()

    return redirect(url_for("matches_index"))