@@ -30,28 +30,33 @@ def to_datetime(value):
30
30
31
31
@app .route ('/' )
32
32
def index ():
33
- return render_template ('index.html' )
33
+ return render_template ('index.html' , clubs = clubs )
34
34
35
35
36
36
@app .route ('/showSummary' , methods = ['POST' ])
37
37
def showSummary ():
38
38
try :
39
39
club = [club for club in clubs if club ['email' ] == request .form ['email' ]][0 ]
40
- return render_template ('welcome.html' , club = club , competitions = competitions , date_now = date_now )
40
+ sorted_competitions = sorted (competitions , key = lambda x : to_datetime (x ['date' ]), reverse = True )
41
+ return render_template ('welcome.html' , club = club , competitions = sorted_competitions , date_now = date_now )
41
42
except IndexError :
42
- flash ("Email not found" )
43
- return redirect (url_for ('index' ))
43
+ if request .form ['email' ] == '' :
44
+ flash ("Please enter a valid email." )
45
+ else :
46
+ flash ("Email not found" )
47
+ return render_template ('index.html' , clubs = clubs ), 401
44
48
45
49
46
50
@app .route ('/book/<competition>/<club>' )
47
51
def book (competition , club ):
48
52
foundClub = [c for c in clubs if c ['name' ] == club ][0 ]
49
53
foundCompetition = [c for c in competitions if c ['name' ] == competition ][0 ]
54
+ sorted_competitions = sorted (competitions , key = lambda x : to_datetime (x ['date' ]), reverse = True )
50
55
if foundClub and foundCompetition :
51
56
return render_template ('booking.html' , club = foundClub , competition = foundCompetition )
52
57
else :
53
58
flash ("Something went wrong-please try again" )
54
- return render_template ('welcome.html' , club = club , competitions = competitions , date_now = date_now )
59
+ return render_template ('welcome.html' , club = club , competitions = sorted_competitions , date_now = date_now )
55
60
56
61
57
62
@app .route ('/purchasePlaces' , methods = ['POST' ])
@@ -71,12 +76,10 @@ def purchasePlaces():
71
76
competition ['numberOfPlaces' ] = int (competition ['numberOfPlaces' ])- placesRequired
72
77
club ["points" ] = int (club ["points" ]) - placesRequired
73
78
flash ('Great-booking complete!' )
74
- return render_template ('welcome.html' , club = club , competitions = competitions , date_now = date_now )
75
-
76
-
77
- # TODO: Add route for points display
79
+ sorted_competitions = sorted (competitions , key = lambda x : to_datetime (x ['date' ]), reverse = True )
80
+ return render_template ('welcome.html' , club = club , competitions = sorted_competitions , date_now = date_now )
78
81
79
82
80
83
@app .route ('/logout' )
81
84
def logout ():
82
- return redirect (url_for ('index' ))
85
+ return redirect (url_for ('index' , clubs = clubs ))
0 commit comments