Skip to content

feat: Implement club points display board and session management #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clubs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Simply Lift",
"email": "[email protected]",
"points": "10"
"points": "6"
},
{
"name": "Iron Temple",
Expand Down
2 changes: 1 addition & 1 deletion competitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{
"name": "Summer 2025",
"date": "2025-07-22 13:30:00",
"numberOfPlaces": 7
"numberOfPlaces": 3
}
]
}
76 changes: 61 additions & 15 deletions server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from flask import Flask,render_template,request,redirect,flash,url_for
from flask import Flask,render_template,request,redirect,flash,url_for,session
from datetime import datetime


Expand Down Expand Up @@ -28,53 +28,90 @@ def saveCompetitions(competitions_data):
competitions = loadCompetitions()
clubs = loadClubs()


@app.route('/')
def index():
if 'club_email' in session:
club_email = session['club_email']
found_clubs = [c for c in clubs if c['email'] == club_email]
if found_clubs:
club = found_clubs[0]
return render_template('welcome.html', club=club, competitions=competitions,
current_date_str=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
else:
session.pop('club_email', None)
flash("Your club's email was not found. Please log in again.")
return render_template('index.html')
return render_template('index.html')


@app.route('/showSummary',methods=['POST'])
def showSummary():
found_clubs = [club for club in clubs if club['email'] == request.form['email']]
user_email = request.form['email']
found_clubs = [club for club in clubs if club['email'] == user_email]

if found_clubs:
club = found_clubs[0]
return render_template('welcome.html',club=club,competitions=competitions, current_date_str=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
session['club_email'] = club['email']
return render_template('welcome.html',club=club,competitions=competitions,
current_date_str=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
else:
flash("Sorry, that email was not found.")
session.pop('club_email', None)
return redirect(url_for('index'))


@app.route('/book/<competition>/<club>')
def book(competition,club):
foundClub = [c for c in clubs if c['name'] == club][0]
foundCompetition = [c for c in competitions if c['name'] == competition][0]
@app.route('/book/<competition_name>/<club_name>')
def book(competition_name,club_name):
if 'club_email' not in session:
flash("You need to be logged in to book places.")
return redirect(url_for('index'))

logged_in_club_email = session['club_email']
foundClub = [c for c in clubs if c['email'] == logged_in_club_email][0]

foundCompetition = [c for c in competitions if c['name'] == competition_name][0]

if foundClub['name'] != club_name:
flash("Attempted to book for a different club. Action blocked.")
return redirect(url_for('index'))

competition_date = datetime.strptime(foundCompetition['date'], '%Y-%m-%d %H:%M:%S')
if competition_date < datetime.now():
flash("This competition has already passed. Booking is not allowed.")
return render_template('welcome.html', club=foundClub, competitions=competitions, current_date_str=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
return redirect(url_for('index'))

if foundClub and foundCompetition:
return render_template('booking.html',club=foundClub,competition=foundCompetition)
else:
flash("Something went wrong-please try again")
return render_template('welcome.html', club=foundClub, competitions=competitions, current_date_str=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
return redirect(url_for('index'))


@app.route('/purchasePlaces',methods=['POST'])
def purchasePlaces():
if 'club_email' not in session:
flash("You need to be logged in to purchase places.")
return redirect(url_for('index'))

logged_in_club_email = session['club_email']
club = [c for c in clubs if c['email'] == logged_in_club_email][0]

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 club['name'] != request.form['club']:
flash("Attempted to purchase for a different club. Action blocked.")
return redirect(url_for('index'))

competition_date = datetime.strptime(competition['date'], '%Y-%m-%d %H:%M:%S')
if competition_date < datetime.now():
flash("Booking for past competitions is not allowed.")
return render_template('welcome.html', club=club, competitions=competitions, current_date_str=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
return redirect(url_for('index'))

if placesRequired > 12:
flash("You cannot book more than 12 places per competition.")
return render_template('welcome.html', club=club, competitions=competitions, current_date_str=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
return redirect(url_for('index'))

if int(club['points']) >= placesRequired:
if int(competition['numberOfPlaces']) >= placesRequired:
Expand All @@ -90,12 +127,21 @@ def purchasePlaces():
else:
flash(f"You do not have enough points to book {placesRequired} places. You currently have {club['points']} points.")

return render_template('welcome.html', club=club, competitions=competitions, current_date_str=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
return redirect(url_for('index'))


# TODO: Add route for points display
@app.route('/pointsDisplay')
def pointsDisplay():
if 'club_email' not in session:
flash("You need to be logged in to view club points.")
return redirect(url_for('index'))

sorted_clubs = sorted(clubs, key=lambda c: int(c['points']), reverse=True)
return render_template('points.html', clubs=sorted_clubs)


@app.route('/logout')
def logout():
return redirect(url_for('index'))
session.pop('club_email', None)
flash("You have been logged out.")
return redirect(url_for('index'))
33 changes: 33 additions & 0 deletions templates/points.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Points Display Board | GUDLFT Registration</title>
</head>
<body>
<h2>Club Points Leaderboard</h2>
<p><a href="{{url_for('index')}}">Back to Dashboard</a></p>

{% if clubs %}
<table border="1" style="width:50%; text-align: left;">
<thead>
<tr>
<th>Club Name</th>
<th>Points</th>
</tr>
</thead>
<tbody>
{% for club_item in clubs %}
<tr>
<td>{{ club_item['name'] }}</td>
<td>{{ club_item['points'] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>No clubs found to display points.</p>
{% endif %}

</body>
</html>
7 changes: 5 additions & 2 deletions templates/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<title>Summary | GUDLFT Registration</title>
</head>
<body>
<h2>Welcome, {{club['email']}} </h2><a href="{{url_for('logout')}}">Logout</a>
<h2>Welcome, {{club['email']}} </h2>
<a href="{{url_for('logout')}}">Logout</a> |
<a href="{{url_for('pointsDisplay')}}">View All Club Points</a>

{% with messages = get_flashed_messages()%}
{% if messages %}
Expand All @@ -25,7 +27,8 @@ <h3>Competitions:</h3>
Number of Places: {{comp['numberOfPlaces']}}
{# Compare competition date string with current_date_str #}
{% if comp['date'] > current_date_str and comp['numberOfPlaces']|int > 0 %}
<a href="{{ url_for('book',competition=comp['name'],club=club['name']) }}">Book Places</a>
{# --- CHANGE THIS LINE --- #}
<a href="{{ url_for('book',competition_name=comp['name'],club_name=club['name']) }}">Book Places</a>
{% else %}
{% if comp['date'] <= current_date_str %}
<span style="color: gray;">(Competition passed)</span>
Expand Down