Skip to content

Commit

Permalink
Fix Bug No negative account OpenClassrooms-Student-Center#2
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBotswana committed Feb 20, 2024
1 parent bc1233a commit d085d32
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,21 @@ def book(competition,club):

@app.route('/purchasePlaces',methods=['POST'])
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!')
return render_template('welcome.html', club=club, competitions=competitions)
try:
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 <= int(club['points']):
competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
club['points'] = int(club['points'])-placesRequired
flash('Great-booking complete!')
return render_template('welcome.html', club=club, competitions=competitions)
else:
flash("You don't have enougth points")
return render_template('welcome.html', club=club, competitions=competitions)
except Exception:
flash("Something went wrong-please try again")
return render_template('welcome.html', club=club, competitions=competitions)


# TODO: Add route for points display
Expand Down

0 comments on commit d085d32

Please sign in to comment.