|
4 | 4 |
|
5 | 5 | def loadClubs():
|
6 | 6 | with open('clubs.json') as c:
|
7 |
| - listOfClubs = json.load(c)['clubs'] |
| 7 | + listOfClubs = json.load(c)["clubs"] |
8 | 8 | return listOfClubs
|
9 | 9 |
|
10 | 10 |
|
11 | 11 | def loadCompetitions():
|
12 | 12 | with open('competitions.json') as comps:
|
13 |
| - listOfCompetitions = json.load(comps)['competitions'] |
| 13 | + listOfCompetitions = json.load(comps)["competitions"] |
14 | 14 | return listOfCompetitions
|
15 | 15 |
|
16 | 16 |
|
@@ -45,8 +45,15 @@ def book(competition,club):
|
45 | 45 | def purchasePlaces():
|
46 | 46 | competition = [c for c in competitions if c['name'] == request.form['competition']][0]
|
47 | 47 | club = [c for c in clubs if c['name'] == request.form['club']][0]
|
| 48 | + if not request.form['places'] or int(request.form['places']) < 1 : |
| 49 | + flash("Places required must be a positive integer") |
| 50 | + return redirect(url_for('book',competition=competition['name'],club=club['name'])) |
48 | 51 | placesRequired = int(request.form['places'])
|
49 |
| - competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired |
| 52 | + if placesRequired > int(club['points']): |
| 53 | + flash("Places required exceed club's total points") |
| 54 | + return redirect(url_for('book',competition=competition['name'],club=club['name'])) |
| 55 | + competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired |
| 56 | + club['points'] = int(club['points']) - placesRequired |
50 | 57 | flash('Great-booking complete!')
|
51 | 58 | return render_template('welcome.html', club=club, competitions=competitions)
|
52 | 59 |
|
|
0 commit comments