summaryrefslogtreecommitdiff
path: root/app.py
diff options
context:
space:
mode:
authorKaran Jayachandra <karan.jayachandra@nxp.com>2024-04-12 10:29:29 +0200
committerKaran Jayachandra <karan.jayachandra@nxp.com>2024-04-12 10:29:29 +0200
commitc58caf5b8b8801ba826b0ff6b241d7f25a333bc8 (patch)
tree45b22248fd4fbcf23046ef30707da8ff1f65c880 /app.py
parente6939bb6421862a12048449094f2c55e6e9e401b (diff)
Added a more cleaner application
Diffstat (limited to 'app.py')
-rw-r--r--app.py73
1 files changed, 30 insertions, 43 deletions
diff --git a/app.py b/app.py
index 6ff3b9a..7d9f808 100644
--- a/app.py
+++ b/app.py
@@ -1,55 +1,42 @@
-from dash import Dash
-from pathlib import PurePath
-from importlib.resources import files
-from match_up.model import PlaySession
-from match_up.view import MainLayout
-from match_up.tests import (
- TEST_DATABASE_LOCATION,
-)
-from dash_bootstrap_components.themes import ZEPHYR
-from flask import Flask, render_template
+from os import getenv
+from model import PlayerList
+from flask import Flask, abort, render_template
+from dotenv import load_dotenv
-DATABASE_LOCATION = "storage.json"
+load_dotenv()
-# class Application:
-# def __init__(self, debug=False):
-# self._debug = debug
-# if debug:
-# database_location = TEST_DATABASE_LOCATION
-# else:
-# database_location = DATABASE_LOCATION
-# self._session = PlaySession(PurePath(database_location))
-# self._dashboard = Dash("Match Up!", external_stylesheets=[ZEPHYR])
-# self._layout = MainLayout(
-# self._session.data.get_players(), self._session.get_matches()
-# )
-# self._dashboard.layout = self._layout.get()
+print("Importing player list...\n")
+PLAYER_LIST = PlayerList(location="test_data.csv")
+print("List of player:\n")
+print(PLAYER_LIST)
-# def run(self):
-# self._dashboard.run(debug=self._debug)
+app = Flask("Match Up! Backend")
+env_config = getenv("PROD_APP_SETTINGS", "config.DevelopmentConfig")
+app.config.from_object(env_config)
-# def main():
-# a = Application(debug=True)
-# a.run()
-
-
-app = Flask("Match Up")
-session = PlaySession(PurePath("test_storage.json"))
-base_template_path = "match_up.templates"
+@app.route("/", methods=["GET"])
+def home():
+ return render_template("index.j2")
-@app.route("/")
-def home():
- print(files(base_template_path).joinpath("index.html").name)
+@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(
- "index.html",
- player_list=session.data.get_players(),
- game_list=session.get_matches(),
+ "player.j2",
+ player=selection[0],
)
-if __name__ == "__main__":
- print("Starting app")
- app.run(host="localhost", debug=True, port=80)
+@app.route("/player-list", methods=["GET"])
+def get_list_of_players():
+ return render_template(
+ "players.j2",
+ players=PLAYER_LIST.players,
+ )