5 Commits

Author SHA1 Message Date
2dc85f19e7 added public list of club`s points 2025-06-26 15:11:13 +02:00
1009e35d17 cleaned an unused print 2025-06-26 12:07:42 +02:00
7521a05db9 added now to every welcome template call 2025-06-26 11:37:02 +02:00
364bdb3d9f past comp is displayed; condition on link and route 2025-06-26 11:26:57 +02:00
0345e8e8df added filter on date in view 2025-06-26 11:13:38 +02:00
4 changed files with 37 additions and 8 deletions

View File

@@ -1,5 +1,6 @@
import json import json
from flask import Flask,render_template,request,redirect,flash,url_for,session from flask import Flask,render_template,request,redirect,flash,url_for,session
from datetime import datetime
def loadClubs(): def loadClubs():
@@ -19,6 +20,8 @@ app.secret_key = 'something_special'
competitions = loadCompetitions() competitions = loadCompetitions()
clubs = loadClubs() clubs = loadClubs()
now = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S")
@app.route('/') @app.route('/')
def index(): def index():
@@ -28,7 +31,7 @@ def index():
def showSummary(): def showSummary():
club = [club for club in clubs if club['email'] == request.form['email']] club = [club for club in clubs if club['email'] == request.form['email']]
if club: if club:
return render_template('welcome.html', club=club[0], competitions=competitions) return render_template('welcome.html', club=club[0], competitions=competitions, now=now)
flash("The email isn't found") flash("The email isn't found")
return redirect(url_for('index')) return redirect(url_for('index'))
@@ -37,10 +40,15 @@ def book(competition,club):
foundClub = [c for c in clubs if c['name'] == club][0] foundClub = [c for c in clubs if c['name'] == club][0]
foundCompetition = [c for c in competitions if c['name'] == competition][0] foundCompetition = [c for c in competitions if c['name'] == competition][0]
if foundClub and foundCompetition: if foundClub and foundCompetition:
return render_template('booking.html',club=foundClub,competition=foundCompetition) if foundCompetition['date'] > now:
return render_template('booking.html',club=foundClub,competition=foundCompetition)
else:
flash("You cannot book for a past competition")
return render_template('welcome.html', club=foundClub,
competitions=competitions, now=now)
else: else:
flash("Something went wrong-please try again") flash("Something went wrong-please try again")
return render_template('welcome.html', club=club, competitions=competitions) return render_template('welcome.html', club=club, competitions=competitions, now=now)
@app.route('/purchasePlaces',methods=['POST']) @app.route('/purchasePlaces',methods=['POST'])
@@ -53,15 +61,15 @@ def purchasePlaces():
else: else:
places = {competition['name']: placesRequired} places = {competition['name']: placesRequired}
points = int(club['points']) points = int(club['points'])
print("booked", places)
if placesRequired <= 12: if placesRequired <= 12:
if places[competition['name']] <= 12: if places[competition['name']] <= 12:
if placesRequired <= points: if placesRequired <= points:
competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired
club['points'] = int(club['points']) - placesRequired club['points'] = int(club['points']) - placesRequired
print(club['points'])
if not competition['name'] in session: if not competition['name'] in session:
session[competition['name']] = placesRequired session[competition['name']] = placesRequired
flash('Great-booking complete!') flash(f"Great ! {placesRequired} places booked for {competition['name']}")
else: else:
flash("You don't have enough points") flash("You don't have enough points")
else: else:
@@ -69,10 +77,12 @@ def purchasePlaces():
else: else:
flash("You can't book more than 12 places") flash("You can't book more than 12 places")
return render_template('welcome.html', club=club, return render_template('welcome.html', club=club,
competitions=competitions) competitions=competitions, now=now)
# TODO: Add route for points display # TODO: Add route for points display
@app.route('/points')
def displayPoints():
return render_template('points.html', clubs=clubs)
@app.route('/logout') @app.route('/logout')
def logout(): def logout():

View File

@@ -22,5 +22,6 @@
<input type="email" name="email" id=""/> <input type="email" name="email" id=""/>
<button type="submit">Enter</button> <button type="submit">Enter</button>
</form> </form>
<a href="{{ url_for('displayPoints') }}">Board of points</a>
</body> </body>
</html> </html>

18
templates/points.html Normal file
View File

@@ -0,0 +1,18 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Board of clubs and points || GUDLFT</title>
</head>
<body>
<h2>Current points</h2>
<ul>
{% for club in clubs %}
<li><strong>club : </strong> {{club['name']}} </br>
<strong>Points : </strong>{{club['points']}}</br>
</br>
{% endfor %}
</ul>
<a href="{{ url_for('index') }}"> Back </a>
</body>
</html>

View File

@@ -23,7 +23,7 @@
{{comp['name']}}<br /> {{comp['name']}}<br />
Date: {{comp['date']}}</br> Date: {{comp['date']}}</br>
Number of Places: {{comp['numberOfPlaces']}} Number of Places: {{comp['numberOfPlaces']}}
{%if comp['numberOfPlaces']|int >0%} {%if comp['numberOfPlaces']|int >0 and comp['date'] > now%}
<a href="{{ url_for('book',competition=comp['name'],club=club['name']) }}">Book Places</a> <a href="{{ url_for('book',competition=comp['name'],club=club['name']) }}">Book Places</a>
{%endif%} {%endif%}
</li> </li>