Skip to content

Commit f33fa57

Browse files
committed
FEATURE: Implement Points Display Board and clean tests OpenClassrooms-Student-Center#7
1 parent 4467b19 commit f33fa57

File tree

4 files changed

+45
-83
lines changed

4 files changed

+45
-83
lines changed

.DS_Store

2 KB
Binary file not shown.

server.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,33 @@ def to_datetime(value):
3030

3131
@app.route('/')
3232
def index():
33-
return render_template('index.html')
33+
return render_template('index.html', clubs=clubs)
3434

3535

3636
@app.route('/showSummary', methods=['POST'])
3737
def showSummary():
3838
try:
3939
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)
4142
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
4448

4549

4650
@app.route('/book/<competition>/<club>')
4751
def book(competition, club):
4852
foundClub = [c for c in clubs if c['name'] == club][0]
4953
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)
5055
if foundClub and foundCompetition:
5156
return render_template('booking.html', club=foundClub, competition=foundCompetition)
5257
else:
5358
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)
5560

5661

5762
@app.route('/purchasePlaces', methods=['POST'])
@@ -71,12 +76,10 @@ def purchasePlaces():
7176
competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
7277
club["points"] = int(club["points"]) - placesRequired
7378
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)
7881

7982

8083
@app.route('/logout')
8184
def logout():
82-
return redirect(url_for('index'))
85+
return redirect(url_for('index', clubs=clubs))

templates/index.html

+32
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,47 @@
22
<head>
33
<meta charset="UTF-8">
44
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
6+
57
<title>GUDLFT Registration</title>
68
</head>
79
<body>
10+
11+
<h1>GUDLFT Club's display board</h1>
12+
13+
<hr>
14+
<table>
15+
<tr>
16+
<th>Club</th>
17+
<th>Points</th>
18+
</tr>
19+
{% for club in clubs %}
20+
<tr>
21+
<td>{{ club['name'] }}</td>
22+
<td>{{ club['points'] }}</td>
23+
</tr>
24+
{% endfor %}
25+
</table>
26+
<hr>
27+
828
<h1>Welcome to the GUDLFT Registration Portal!</h1>
29+
30+
{% with messages = get_flashed_messages()%}
31+
{% if messages %}
32+
<ul>
33+
{% for message in messages %}
34+
<li>{{message}}</li>
35+
{% endfor %}
36+
</ul>
37+
{% endif%}
38+
{%endwith%}
39+
940
Please enter your secretary email to continue:
1041
<form action="showSummary" method="post">
1142
<label for="email">Email:</label>
1243
<input type="email" name="email" id=""/>
1344
<button type="submit">Enter</button>
1445
</form>
46+
1547
</body>
1648
</html>

tests.py

-73
This file was deleted.

0 commit comments

Comments
 (0)