|
|
|
|
@@ -1,5 +1,6 @@
|
|
|
|
|
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():
|
|
|
|
|
@@ -19,6 +20,8 @@ app.secret_key = 'something_special'
|
|
|
|
|
|
|
|
|
|
competitions = loadCompetitions()
|
|
|
|
|
clubs = loadClubs()
|
|
|
|
|
now = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
|
def index():
|
|
|
|
|
@@ -28,7 +31,7 @@ def index():
|
|
|
|
|
def showSummary():
|
|
|
|
|
club = [club for club in clubs if club['email'] == request.form['email']]
|
|
|
|
|
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")
|
|
|
|
|
return redirect(url_for('index'))
|
|
|
|
|
|
|
|
|
|
@@ -37,10 +40,15 @@ 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]
|
|
|
|
|
if foundClub and 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:
|
|
|
|
|
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'])
|
|
|
|
|
@@ -48,10 +56,28 @@ def purchasePlaces():
|
|
|
|
|
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'])
|
|
|
|
|
competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
|
|
|
|
|
flash('Great-booking complete!')
|
|
|
|
|
return render_template('welcome.html', club=club, competitions=competitions)
|
|
|
|
|
|
|
|
|
|
if competition['name'] in session:
|
|
|
|
|
places = {competition['name']: session[competition['name']] + placesRequired}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
@@ -59,3 +85,6 @@ def purchasePlaces():
|
|
|
|
|
@app.route('/logout')
|
|
|
|
|
def logout():
|
|
|
|
|
return redirect(url_for('index'))
|
|
|
|
|
|
|
|
|
|
if (__name__ == "__main__"):
|
|
|
|
|
app.run(debug=True)
|
|
|
|
|
|