From 0db0ff2f1c712273ac48cb859c24253b1efa8384 Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Fri, 11 Oct 2024 16:59:45 +0200 Subject: First working version with court selection --- app.py | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'app.py') diff --git a/app.py b/app.py index 16659ec..9f4caed 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,5 @@ from os import getenv -from model import PlayerList, GameList +from model import CourtList, PlayerList, GameList from flask import Flask, abort, render_template, request from dotenv import load_dotenv @@ -8,7 +8,8 @@ load_dotenv() print("Importing player list...\n") PLAYER_LIST = PlayerList(location="test_data.csv") -GAME_GENERATOR = GameList() +COURT_LIST = CourtList(12) +GAME_GENERATOR = GameList(COURT_LIST) print("List of player:\n") print(PLAYER_LIST) @@ -22,21 +23,9 @@ def home(): return render_template("index.j2") -# @app.route("/courts", methods=["POST"]) -# def set_courts(): -# print(request) -# print(request.data) -# print(request.json) -# print(request.args) -# return render_template( -# "courts.j2", -# courts=GAME_GENERATOR.courts, -# ) - - @app.route("/new-games", methods=["POST"]) def get_new_games(): - GAME_GENERATOR.create_games(PLAYER_LIST.get_active_players()) + GAME_GENERATOR.create_games(COURT_LIST, PLAYER_LIST) return render_template( "games.j2", games=GAME_GENERATOR.games, @@ -70,3 +59,29 @@ def get_list_of_players(): "players.j2", players=PLAYER_LIST.players, ) + + +@app.route("/court-toggle/", 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, + ) -- cgit v1.3.1