diff --git a/server.py b/server.py index 4b7168b..9b1a79e 100644 --- a/server.py +++ b/server.py @@ -28,10 +28,7 @@ def index(): def showSummary(): try: club = [club for club in clubs if club['email'] == request.form['email']][0] - # if club: return render_template('welcome.html', club=club, competitions=competitions) - # flash("Sorry, that email wasn't found") - # return redirect(url_for('index')) except IndexError: flash("Sorry, that email wasn't found") return redirect(url_for('index')) @@ -52,11 +49,18 @@ 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!') + points = int(club['points']) + if placesRequired <= points: + competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired + if competition['numberOfPlaces'] < 0: + competition['numberOfPlaces'] = 0 + flash("Great-booking complete!") + else: + flash("You don't have enough points") return render_template('welcome.html', club=club, competitions=competitions) + # TODO: Add route for points display diff --git a/templates/welcome.html b/templates/welcome.html index d9e8d2f..da2841d 100644 --- a/templates/welcome.html +++ b/templates/welcome.html @@ -15,7 +15,7 @@ {% endfor %} {% endif%} - Points available: {{club['points']}} + Points available: {{club['points']}}

Competitions: