diff --git a/.gitignore b/.gitignore index 2cba99d87..e7e28eb67 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,6 @@ bin include lib .Python -tests/ .envrc -__pycache__ \ No newline at end of file +__pycache__ +.idea/ \ No newline at end of file diff --git a/clubs.json b/clubs.json index 1d7ad1ffe..1e7f3a13f 100644 --- a/clubs.json +++ b/clubs.json @@ -11,6 +11,6 @@ }, { "name":"She Lifts", "email": "kate@shelifts.co.uk", - "points":"12" + "points":"15" } ]} \ No newline at end of file diff --git a/server.py b/server.py index 4084baeac..90223ae41 100644 --- a/server.py +++ b/server.py @@ -26,7 +26,13 @@ def index(): @app.route('/showSummary',methods=['POST']) def showSummary(): - club = [club for club in clubs if club['email'] == request.form['email']][0] + + club = next((club for club in clubs if club['email'] == request.form['email']), None) + + if club is None: + flash("Sorry, that email was not found.") + return render_template("index.html", error="Email not found"), 404 + return render_template('welcome.html',club=club,competitions=competitions) @@ -46,6 +52,15 @@ 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']) + + if placesRequired > 12: + flash("Sorry, you are not allow to purchase more than 12 places.") + return render_template('welcome.html', club=club, competitions=competitions, error="Places max reached"), 403 + + elif placesRequired > int(club['points']): + flash("Sorry, you do not have enough points to purchase.") + return render_template('welcome.html', club=club, competitions=competitions, error="Points not enough"), 403 + competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired flash('Great-booking complete!') return render_template('welcome.html', club=club, competitions=competitions) diff --git a/templates/index.html b/templates/index.html index 926526b7d..56b19b23c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,6 +6,17 @@