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!")
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")
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)
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)
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)