Compare commits
11 Commits
main
...
bug/issue6
Author | SHA1 | Date | |
---|---|---|---|
9d49f5f79f | |||
e089e78fc5 | |||
1009e35d17 | |||
7521a05db9 | |||
364bdb3d9f | |||
0345e8e8df | |||
e6d4d05917 | |||
5102e366e8 | |||
b70f80f3cb | |||
2317006de9 | |||
a50d1946ce |
@ -7,7 +7,7 @@
|
|||||||
{
|
{
|
||||||
"name":"Iron Temple",
|
"name":"Iron Temple",
|
||||||
"email": "admin@irontemple.com",
|
"email": "admin@irontemple.com",
|
||||||
"points":"4"
|
"points":"47"
|
||||||
},
|
},
|
||||||
{ "name":"She Lifts",
|
{ "name":"She Lifts",
|
||||||
"email": "kate@shelifts.co.uk",
|
"email": "kate@shelifts.co.uk",
|
||||||
|
51
server.py
51
server.py
@ -1,5 +1,6 @@
|
|||||||
import json
|
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
|
||||||
|
|
||||||
|
|
||||||
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():
|
||||||
@ -26,19 +29,26 @@ def index():
|
|||||||
|
|
||||||
@app.route('/showSummary',methods=['POST'])
|
@app.route('/showSummary',methods=['POST'])
|
||||||
def showSummary():
|
def showSummary():
|
||||||
club = [club for club in clubs if club['email'] == request.form['email']][0]
|
club = [club for club in clubs if club['email'] == request.form['email']]
|
||||||
return render_template('welcome.html',club=club,competitions=competitions)
|
if club:
|
||||||
|
return render_template('welcome.html', club=club[0], competitions=competitions, now=now)
|
||||||
|
flash("The email isn't found")
|
||||||
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
@app.route('/book/<competition>/<club>')
|
@app.route('/book/<competition>/<club>')
|
||||||
def book(competition,club):
|
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'])
|
||||||
@ -46,10 +56,28 @@ def purchasePlaces():
|
|||||||
competition = [c for c in competitions if c['name'] == request.form['competition']][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]
|
club = [c for c in clubs if c['name'] == request.form['club']][0]
|
||||||
placesRequired = int(request.form['places'])
|
placesRequired = int(request.form['places'])
|
||||||
competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
|
if competition['name'] in session:
|
||||||
flash('Great-booking complete!')
|
places = {competition['name']: session[competition['name']] + placesRequired}
|
||||||
return render_template('welcome.html', club=club, competitions=competitions)
|
else:
|
||||||
|
places = {competition['name']: placesRequired}
|
||||||
|
points = int(club['points'])
|
||||||
|
if placesRequired <= 12:
|
||||||
|
if places[competition['name']] <= 12:
|
||||||
|
if placesRequired <= points:
|
||||||
|
competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired
|
||||||
|
club['points'] = int(club['points']) - placesRequired
|
||||||
|
print(club['points'])
|
||||||
|
if not competition['name'] in session:
|
||||||
|
session[competition['name']] = placesRequired
|
||||||
|
flash(f"Great ! {placesRequired} places booked for {competition['name']}")
|
||||||
|
else:
|
||||||
|
flash("You don't have enough points")
|
||||||
|
else:
|
||||||
|
flash(f"You already booked 12 places for {competition['name']}")
|
||||||
|
else:
|
||||||
|
flash("You can't book more than 12 places")
|
||||||
|
return render_template('welcome.html', club=club,
|
||||||
|
competitions=competitions, now=now)
|
||||||
|
|
||||||
# TODO: Add route for points display
|
# TODO: Add route for points display
|
||||||
|
|
||||||
@ -57,3 +85,6 @@ def purchasePlaces():
|
|||||||
@app.route('/logout')
|
@app.route('/logout')
|
||||||
def logout():
|
def logout():
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
if (__name__ == "__main__"):
|
||||||
|
app.run(debug=True)
|
||||||
|
@ -6,6 +6,16 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Welcome to the GUDLFT Registration Portal!</h1>
|
<h1>Welcome to the GUDLFT Registration Portal!</h1>
|
||||||
|
{% with messages = get_flashed_messages()%}
|
||||||
|
{% if messages %}
|
||||||
|
<ul>
|
||||||
|
{% for message in messages %}
|
||||||
|
<li>{{message}}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif%}
|
||||||
|
{% endwith %}
|
||||||
|
|
||||||
Please enter your secretary email to continue:
|
Please enter your secretary email to continue:
|
||||||
<form action="showSummary" method="post">
|
<form action="showSummary" method="post">
|
||||||
<label for="email">Email:</label>
|
<label for="email">Email:</label>
|
||||||
|
@ -10,10 +10,10 @@
|
|||||||
{% with messages = get_flashed_messages()%}
|
{% with messages = get_flashed_messages()%}
|
||||||
{% if messages %}
|
{% if messages %}
|
||||||
<ul>
|
<ul>
|
||||||
{% for message in messages %}
|
{% for message in messages %}
|
||||||
<li>{{message}}</li>
|
<li>{{message}}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif%}
|
{% endif%}
|
||||||
Points available: {{club['points']}}
|
Points available: {{club['points']}}
|
||||||
<h3>Competitions:</h3>
|
<h3>Competitions:</h3>
|
||||||
@ -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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user