summaryrefslogtreecommitdiff
path: root/app.py
diff options
context:
space:
mode:
Diffstat (limited to 'app.py')
-rw-r--r--app.py32
1 files changed, 14 insertions, 18 deletions
diff --git a/app.py b/app.py
index 6c1609a..5c39c0d 100644
--- a/app.py
+++ b/app.py
@@ -6,10 +6,10 @@ from model import CourtList, PlayerList, GameList
load_dotenv()
-PLAYER_LIST = PlayerList(location="test_data_large.csv")
-COURT_LIST = CourtList(12)
+PLAYERS = PlayerList(location="test_data_large.csv")
+COURTS = CourtList(12)
GAME_GENERATOR = GameList()
-GAME_GENERATOR.clear(COURT_LIST)
+GAME_GENERATOR.clear(COURTS)
app = Flask("Match Up! Backend")
@@ -25,21 +25,21 @@ def home():
@app.route("/random-games", methods=["POST"])
def get_random_games():
print("Creating new games...")
- GAME_GENERATOR.create_random_games(COURT_LIST, PLAYER_LIST)
+ GAME_GENERATOR.create_random_games(COURTS, PLAYERS)
return render_template("games.j2", games=GAME_GENERATOR.games)
@app.route("/skilled-games", methods=["POST"])
def get_skilled_games():
print("Creating new games...")
- GAME_GENERATOR.create_skilled_games(COURT_LIST, PLAYER_LIST)
+ GAME_GENERATOR.create_skilled_games(COURTS, PLAYERS)
return render_template("games.j2", games=GAME_GENERATOR.games)
@app.route("/clear-games", methods=["POST"])
def clear_games():
print("Clearing games...")
- GAME_GENERATOR.clear(COURT_LIST)
+ GAME_GENERATOR.clear(COURTS)
return render_template("games.j2", games=GAME_GENERATOR.games)
@@ -50,30 +50,26 @@ def get_list_of_games():
@app.route("/player-toggle/<player_request>", methods=["POST"])
def toggle_player(player_request):
- selection = PLAYER_LIST.get_player(player_request)
+ selection = PLAYERS.get_player(player_request)
if len(selection) != 1:
abort(404)
- PLAYER_LIST.toggle_player(player_request)
- selection = PLAYER_LIST.get_player(player_request)
+ PLAYERS.toggle_player(player_request)
+ selection = PLAYERS.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)
+ return render_template("players.j2", players=PLAYERS.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)
- if len(selection) != 1:
- abort(404, f"Multiple courts requested: {len(selection)}")
- COURT_LIST.toggle_court(court_number)
- selection = COURT_LIST.get_court(court_number)
- return render_template("court.j2", court=selection[0])
+ id = int(court_number)
+ status = COURTS.toggle_court_status(id)
+ return render_template("court.j2", id=id, status=status)
@app.route("/court-list", methods=["GET"])
def get_list_of_courts():
- return render_template("courts.j2", courts=COURT_LIST.courts)
+ return render_template("courts.j2", courts=COURTS.courts)