示例#1
0
def stadiums():
    if request.method == 'GET':
        stadiums = get_stadiums_db()
        return render_template("stadiums.html", stadiums=stadiums)
    if request.method == 'POST':
        if not request.form['stadium_name']:
            stadiums = get_stadiums_db()
            return render_template("stadiums.html", stadiums=stadiums, error="Stadium name can not be empty!")
        stadium_name = request.form['stadium_name']
        stadium = Stadium(stadium_name)
        try:
            insert_stadiums_db(stadium)
            flash("Stadium successfully added!")
            stadiums = get_stadiums_db()
            return render_template("stadiums.html", stadiums=stadiums)
        except psycopg2.errors.UniqueViolation:
            stadiums = get_stadiums_db()
            return render_template("stadiums.html", stadiums=stadiums, error="Stadium name must be different!")
示例#2
0
def edit_matches():
    username = request.form['user_name']
    if get_player_with_username(username):
        update_appointments_db(request.form['match_id'], request.form['user_name'])
    else:
        teams = get_teams_db()
        matchs = get_appointments_db()
        stadiums = get_stadiums_db()
        return render_template("matches.html", matchs=matchs, teams=teams, stadiums=stadiums, error="You need to create a player profile!")
    return redirect("matches")
示例#3
0
def matches():
    if request.method == 'POST':
        teams = get_teams_db()
        match = Match(request.form['team_home'], request.form['team_away'])
        match_id = insert_match_db(match)
        stadiums = get_stadiums_db()
        stadium_id = get_stad_id_with_stad_name(request.form['stadium_name'])
        appointment = Appointment(request.form['appointment_name'], match_id, stadium_id, request.form['start_time'], request.form['end_time'], request.form['match_date'])
        if not request.form['appointment_name']:
            matchs = get_appointments_db()
            return render_template("matches.html", matchs=matchs, teams=teams, stadiums=stadiums, error="Appointment name can not be empty!")
        try:
            insert_appointments_db(appointment)
            flash("Appointment successfully created!")
            matchs = get_appointments_db()
        except psycopg2.errors.UniqueViolation:
            matchs = get_appointments_db()
            return render_template("matches.html", matchs=matchs, teams=teams, stadiums=stadiums, error="Appointment name already exists!")
        return render_template("matches.html", matchs=matchs, teams=teams, stadiums=stadiums)
    if request.method == 'GET':
        teams = get_teams_db()
        matchs = get_appointments_db()
        stadiums = get_stadiums_db()
        return render_template("matches.html", matchs=matchs, teams=teams, stadiums=stadiums)
示例#4
0
def update_stadiums():
    new_stad_name = request.form['new_stadium_name']
    update_stadiums_db(request.form['old_stadium_name'], new_stad_name)
    stadiums = get_stadiums_db()
    flash("Stadium name successfully updated!")
    return render_template("stadiums.html", stadiums=stadiums)
示例#5
0
def delete_stadiums():
    stadium_name = request.form['stadium_name'] 
    delete_stadium_db(stadium_name)
    stadiums = get_stadiums_db()
    flash("Stadium " + stadium_name + " successfully deleted!")
    return render_template("stadiums.html", stadiums=stadiums)