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
76
77
78
79
80
81
82
83
84
85
86
87
|
from os import getenv
from model import CourtList, PlayerList, GameList
from flask import Flask, abort, render_template, request
from dotenv import load_dotenv
load_dotenv()
print("Importing player list...\n")
PLAYER_LIST = PlayerList(location="test_data.csv")
COURT_LIST = CourtList(12)
GAME_GENERATOR = GameList(COURT_LIST)
print("List of player:\n")
print(PLAYER_LIST)
app = Flask("Match Up! Backend")
env_config = getenv("PROD_APP_SETTINGS", "config.DevelopmentConfig")
app.config.from_object(env_config)
@app.route("/", methods=["GET"])
def home():
return render_template("index.j2")
@app.route("/new-games", methods=["POST"])
def get_new_games():
GAME_GENERATOR.create_games(COURT_LIST, PLAYER_LIST)
return render_template(
"games.j2",
games=GAME_GENERATOR.games,
)
@app.route("/game-list", methods=["GET"])
def get_list_of_games():
return render_template(
"games.j2",
games=GAME_GENERATOR.games,
)
@app.route("/player-toggle/<player_request>", methods=["POST"])
def toggle_player(player_request):
selection = PLAYER_LIST.get_player(player_request)
if len(selection) != 1:
abort(404)
PLAYER_LIST.toggle_player(player_request)
selection = PLAYER_LIST.get_player(player_request)
return render_template(
"player.j2",
player=selection[0],
)
@app.route("/player-list", methods=["GET"])
def get_list_of_players():
return render_template(
"players.j2",
players=PLAYER_LIST.players,
)
@app.route("/court-toggle/<court_number>", methods=["POST"])
def toggle_court(court_number):
court_number = int(court_number)
selection = COURT_LIST.get_court(court_number)
print(len(selection))
print(selection)
if len(selection) != 1:
abort(404, f"Multiple courts requested: {len(selection)}")
print(COURT_LIST.courts)
COURT_LIST.toggle_court(court_number)
print(COURT_LIST.courts)
selection = COURT_LIST.get_court(court_number)
return render_template(
"court.j2",
court=selection[0],
)
@app.route("/court-list", methods=["GET"])
def get_list_of_courts():
return render_template(
"courts.j2",
courts=COURT_LIST.courts,
)
|