summaryrefslogtreecommitdiff
path: root/app.py
diff options
context:
space:
mode:
authorKaran Jayachandra <karan.jayachandra@nxp.com>2024-10-15 12:07:42 +0200
committerKaran Jayachandra <karan.jayachandra@nxp.com>2024-10-15 12:07:42 +0200
commit600b6afff3066d5fc9c4eca659f969322e670a77 (patch)
tree1bccadf85e486520d747bd1144ae98c7d0ad969b /app.py
parentccdf8fcb51a47b79d5a1c0042699b0d60c3c304c (diff)
Cleaned up the code significantly
Diffstat (limited to 'app.py')
-rw-r--r--app.py58
1 files changed, 19 insertions, 39 deletions
diff --git a/app.py b/app.py
index 5c39c0d..85dd4f0 100644
--- a/app.py
+++ b/app.py
@@ -1,20 +1,18 @@
from os import getenv
+from controller import Session
from dotenv import load_dotenv
-from flask import Flask, abort, render_template
-from model import CourtList, PlayerList, GameList
+from model import CourtList, PlayerList
+from flask import Flask, render_template, request
+
load_dotenv()
-PLAYERS = PlayerList(location="test_data_large.csv")
-COURTS = CourtList(12)
-GAME_GENERATOR = GameList()
-GAME_GENERATOR.clear(COURTS)
+S = Session(courts=CourtList(12), players=PlayerList("test_data_large.csv"))
app = Flask("Match Up! Backend")
-env_config = getenv("PROD_APP_SETTINGS", "config.DevelopmentConfig")
-app.config.from_object(env_config)
+app.config.from_object(getenv("PROD_APP_SETTINGS", "config.DevelopmentConfig"))
@app.route("/", methods=["GET"])
@@ -22,54 +20,36 @@ def home():
return render_template("index.j2")
-@app.route("/random-games", methods=["POST"])
+@app.route("/propose", methods=["POST"])
def get_random_games():
- print("Creating new games...")
- 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(COURTS, PLAYERS)
- return render_template("games.j2", games=GAME_GENERATOR.games)
+ levels = int(request.form["type"].split()[0])
+ return render_template("games.j2", title="Proposal", games=S.propose_round(levels))
-@app.route("/clear-games", methods=["POST"])
+@app.route("/clear", methods=["POST"])
def clear_games():
- print("Clearing games...")
- GAME_GENERATOR.clear(COURTS)
- 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)
+ return render_template("games.j2", title=f"Round: {S.round}", games=S.clear_round())
@app.route("/player-toggle/<player_request>", methods=["POST"])
def toggle_player(player_request):
- selection = PLAYERS.get_player(player_request)
- if len(selection) != 1:
- abort(404)
- PLAYERS.toggle_player(player_request)
- selection = PLAYERS.get_player(player_request)
- return render_template("player.j2", player=selection[0])
+ id = int(player_request)
+ status, name = S.players.toggle_player_status(id)
+ return render_template("player.j2", id=id, status=status, name=name)
-@app.route("/player-list", methods=["GET"])
+@app.route("/players", methods=["GET"])
def get_list_of_players():
- return render_template("players.j2", players=PLAYERS.players)
+ return render_template("players.j2", players=S.players.get_players())
@app.route("/court-toggle/<court_number>", methods=["POST"])
def toggle_court(court_number):
id = int(court_number)
- status = COURTS.toggle_court_status(id)
+ status = S.courts.toggle_court_status(id)
return render_template("court.j2", id=id, status=status)
-@app.route("/court-list", methods=["GET"])
+@app.route("/courts", methods=["GET"])
def get_list_of_courts():
- return render_template("courts.j2", courts=COURTS.courts)
+ return render_template("courts.j2", courts=S.courts.get_courts())