-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy pathserver.py
75 lines (55 loc) · 2.17 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import json
from flask import Flask,render_template,request,redirect,flash,url_for
def loadClubs():
with open('clubs.json') as c:
listOfClubs = json.load(c)['clubs']
return listOfClubs
def loadCompetitions():
with open('competitions.json') as comps:
listOfCompetitions = json.load(comps)['competitions']
return listOfCompetitions
app = Flask(__name__)
app.secret_key = 'something_special'
competitions = loadCompetitions()
clubs = loadClubs()
@app.route('/')
def index():
return render_template('index.html')
@app.route('/showSummary',methods=['POST'])
def showSummary():
club = [club for club in clubs if club['email'] == request.form['email']][0]
return render_template('welcome.html',club=club,competitions=competitions)
@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]
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=club, competitions=competitions)
@app.route('/purchasePlaces',methods=['POST'])
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'])
if int(club['points']) < placesRequired:
flash("You do not have enough points to book that many places.")
return render_template(
'welcome.html', club=club, competitions=competitions
)
club['points'] = int(club['points']) - placesRequired
competition['numberOfPlaces'] = (
int(competition['numberOfPlaces']) - placesRequired
)
flash('Great - booking complete !')
return render_template(
'welcome.html', club=club, competitions=competitions
)
# TODO: Add route for points display
@app.route('/logout')
def logout():
return redirect(url_for('index'))