diff --git a/.gitignore b/.gitignore index 2cba99d87..09821350e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ lib .Python tests/ .envrc -__pycache__ \ No newline at end of file +__pycache__ +venv/ \ No newline at end of file diff --git a/server.py b/server.py index 4084baeac..54a8f5fa8 100644 --- a/server.py +++ b/server.py @@ -26,9 +26,13 @@ def index(): @app.route('/showSummary',methods=['POST']) def showSummary(): - club = [club for club in clubs if club['email'] == request.form['email']][0] - return render_template('welcome.html',club=club,competitions=competitions) - + found_clubs = [club for club in clubs if club['email'] == request.form['email']] + if found_clubs: + club = found_clubs[0] + return render_template('welcome.html',club=club,competitions=competitions) + else: + flash("Sorry, that email was not found.") + return redirect(url_for('index')) @app.route('/book//') def book(competition,club): @@ -46,11 +50,20 @@ def purchasePlaces(): competition = [c for c in competitions if c['name'] == request.form['competition']][0] club = [c for c in clubs if c['name'] == request.form['club']][0] placesRequired = int(request.form['places']) - competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired - flash('Great-booking complete!') + if placesRequired > 12: + flash("You cannot book more than 12 places per competition.") + return render_template('welcome.html', club=club, competitions=competitions) + if int(club['points']) >= placesRequired: + competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired + club['points'] = str(int(club['points']) - placesRequired) + flash('Great-booking complete!') + else: + flash(f"You do not have enough points to book {placesRequired} places. You currently have {club['points']} points.") + return render_template('welcome.html', club=club, competitions=competitions) + # TODO: Add route for points display diff --git a/templates/index.html b/templates/index.html index 926526b7d..2ee8e0e12 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,6 +6,18 @@

Welcome to the GUDLFT Registration Portal!

+ + {# Add this block to display flashed messages #} + {% with messages = get_flashed_messages()%} + {% if messages %} + + {% endif%} + {%endwith%} + Please enter your secretary email to continue: