1
1
import json
2
- from flask import Flask ,render_template ,request ,redirect ,flash ,url_for
2
+ from flask import Flask , render_template , request , redirect , flash , url_for
3
3
4
4
5
5
def loadClubs ():
6
6
with open ('clubs.json' ) as c :
7
- listOfClubs = json .load (c )['clubs' ]
8
- return listOfClubs
7
+ listOfClubs = json .load (c )['clubs' ]
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' ]
14
- return listOfCompetitions
13
+ listOfCompetitions = json .load (comps )['competitions' ]
14
+ return listOfCompetitions
15
15
16
16
17
17
app = Flask (__name__ )
@@ -20,40 +20,57 @@ def loadCompetitions():
20
20
competitions = loadCompetitions ()
21
21
clubs = loadClubs ()
22
22
23
+
23
24
@app .route ('/' )
24
25
def index ():
25
26
return render_template ('index.html' )
26
27
27
- @app .route ('/showSummary' ,methods = ['POST' ])
28
+
29
+ @app .route ('/showSummary' , methods = ['POST' ])
28
30
def showSummary ():
29
- club = [club for club in clubs if club ['email' ] == request .form ['email' ]][0 ]
30
- return render_template ('welcome.html' ,club = club ,competitions = competitions )
31
+ club = [club for club in clubs if club ['email' ] == request .form ['email' ]][
32
+ 0 ]
33
+ return render_template ('welcome.html' , club = club ,
34
+ competitions = competitions )
31
35
32
36
33
37
@app .route ('/book/<competition>/<club>' )
34
- def book (competition ,club ):
38
+ def book (competition , club ):
35
39
foundClub = [c for c in clubs if c ['name' ] == club ][0 ]
36
40
foundCompetition = [c for c in competitions if c ['name' ] == competition ][0 ]
37
41
if foundClub and foundCompetition :
38
- return render_template ('booking.html' ,club = foundClub ,competition = foundCompetition )
42
+ return render_template ('booking.html' , club = foundClub ,
43
+ competition = foundCompetition )
39
44
else :
40
45
flash ("Something went wrong-please try again" )
41
- return render_template ('welcome.html' , club = club , competitions = competitions )
46
+ return render_template ('welcome.html' , club = club ,
47
+ competitions = competitions )
42
48
43
49
44
- @app .route ('/purchasePlaces' ,methods = ['POST' ])
50
+ @app .route ('/purchasePlaces' , methods = ['POST' ])
45
51
def purchasePlaces ():
46
- competition = [c for c in competitions if c ['name' ] == request .form ['competition' ]][0 ]
52
+ competition = \
53
+ [c for c in competitions if c ['name' ] == request .form ['competition' ]][0 ]
47
54
club = [c for c in clubs if c ['name' ] == request .form ['club' ]][0 ]
55
+
48
56
placesRequired = int (request .form ['places' ])
49
- competition ['numberOfPlaces' ] = int (competition ['numberOfPlaces' ])- placesRequired
57
+
58
+ if placesRequired > 12 :
59
+ flash ('Max purchase 12.' )
60
+ return render_template ('welcome.html' , club = club ,
61
+ competitions = competitions )
62
+
63
+ competition ['numberOfPlaces' ] = int (
64
+ competition ['numberOfPlaces' ]) - placesRequired
50
65
flash ('Great-booking complete!' )
51
- return render_template ('welcome.html' , club = club , competitions = competitions )
66
+
67
+ return render_template ('welcome.html' , club = club ,
68
+ competitions = competitions )
52
69
53
70
54
71
# TODO: Add route for points display
55
72
56
73
57
74
@app .route ('/logout' )
58
75
def logout ():
59
- return redirect (url_for ('index' ))
76
+ return redirect (url_for ('index' ))
0 commit comments