aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pyproject.toml4
-rw-r--r--src/match_up/__init__.py20
-rw-r--r--src/match_up/templates/index.j24
-rw-r--r--src/match_up/templates/macros.j24
-rw-r--r--src/match_up/templates/players.j24
5 files changed, 21 insertions, 15 deletions
diff --git a/pyproject.toml b/pyproject.toml
index 9ef21d8..9e8a793 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -26,8 +26,8 @@ Issues = "https://gitlab.com/KaranJayachandra/match_up/-/issues"
where = ["src"]
[tool.setuptools.package-data]
-"*" = ["*.txt"]
-mypkg1 = ["data1.rst"]
+"templates" = ["*.j2"]
+"static" = ["*.css", "*.js", "*.png", "*.ico"]
[project.scripts]
match_up = "match_up:main" \ No newline at end of file
diff --git a/src/match_up/__init__.py b/src/match_up/__init__.py
index badf3f0..3a78b8d 100644
--- a/src/match_up/__init__.py
+++ b/src/match_up/__init__.py
@@ -1,19 +1,24 @@
from dotenv import load_dotenv
+from importlib.resources import path
from match_up.controller import RoundGenerator
from match_up.model import CourtList, PlayerList
-from jinja2 import FileSystemLoader, Environment
-from flask import Flask, render_template, request
-
+from jinja2 import FileSystemLoader, Environment, PackageLoader
+from flask import Flask, render_template, request, url_for
load_dotenv()
-app = Flask("Match Up! Backend")
+with path("match_up", "static") as p:
+ static_folder = p
+with path("match_up", "templates") as p:
+ template_folder = p
+app = Flask("Match Up! Backend", static_folder=static_folder, template_folder=template_folder)
rg = RoundGenerator(courts=CourtList(), players=PlayerList())
-re = Environment(loader=FileSystemLoader("templates"))
+re = Environment(loader=PackageLoader("match_up"))
@app.route("/", methods=["GET"])
def home():
- return render_template("index.j2")
+ template = re.get_template("index.j2").render(url_for=url_for)
+ return template
@app.route("/time", methods=["GET"])
@@ -74,7 +79,8 @@ def toggle_player(player_request):
@app.route("/players", methods=["GET"])
def get_list_of_players():
- return render_template("players.j2", players=rg.players.get_players())
+ template = re.get_template("players.j2").render(players=rg.players.get_players(), url_for=url_for)
+ return template
@app.route("/court-toggle/<court_number>", methods=["POST"])
diff --git a/src/match_up/templates/index.j2 b/src/match_up/templates/index.j2
index 832dbfb..ce0d531 100644
--- a/src/match_up/templates/index.j2
+++ b/src/match_up/templates/index.j2
@@ -1,10 +1,10 @@
{% from "macros.j2" import header, footer, navbar %}
<!doctype html>
<html lang="en">
- {{ header() }}
+ {{ header(url_for) }}
<body>
<section class="section">
- {{ navbar() }}
+ {{ navbar(url_for) }}
<div hx-post="/clear" hx-swap="outerHTML" hx-trigger="load"></div>
<div hx-get="/control" hx-swap="outerHTML" hx-trigger="load"></div>
{{ footer() }}
diff --git a/src/match_up/templates/macros.j2 b/src/match_up/templates/macros.j2
index 8d05bb0..dedbf48 100644
--- a/src/match_up/templates/macros.j2
+++ b/src/match_up/templates/macros.j2
@@ -22,7 +22,7 @@
</div>
{%- endmacro %}
-{% macro header() -%}
+{% macro header(url_for) -%}
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
@@ -38,7 +38,7 @@
<div class="content has-text-centered">Made by <a href="https://karanjayachandra.com/">Karan</a> using <a href="https://flask.palletsprojects.com">Flask</a>, <a href="https://htmx.org/">HTMX</a> and <a href="https://bulma.io">Bulma</a></div>
{%- endmacro %}
-{% macro navbar() -%}
+{% macro navbar(url_for) -%}
<nav class="level">
<div class="level-left">
<div class="level-item">
diff --git a/src/match_up/templates/players.j2 b/src/match_up/templates/players.j2
index ae6afe0..0d1f96c 100644
--- a/src/match_up/templates/players.j2
+++ b/src/match_up/templates/players.j2
@@ -1,10 +1,10 @@
{% from "macros.j2" import header, navbar, footer, player %}
<!doctype html>
<html lang="en">
- {{ header() }}
+ {{ header(url_for) }}
<body>
<section class="section">
- {{ navbar() }}
+ {{ navbar(url_for) }}
<div class="fixed-grid has-4-cols">
<div class="grid">
{% for id, value in players.items() %}