From 60a489cfb3fb7a12a06212c2c7ed3c05cd0757b5 Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Fri, 25 Oct 2024 18:03:18 +0200 Subject: Moved the files into a folder structure --- src/match_up/templates/controls.j2 | 56 +++++++++++++++++++++++++++++++ src/match_up/templates/games.j2 | 21 ++++++++++++ src/match_up/templates/index.j2 | 13 ++++++++ src/match_up/templates/macros.j2 | 67 ++++++++++++++++++++++++++++++++++++++ src/match_up/templates/players.j2 | 17 ++++++++++ 5 files changed, 174 insertions(+) create mode 100644 src/match_up/templates/controls.j2 create mode 100644 src/match_up/templates/games.j2 create mode 100644 src/match_up/templates/index.j2 create mode 100644 src/match_up/templates/macros.j2 create mode 100644 src/match_up/templates/players.j2 (limited to 'src/match_up/templates') diff --git a/src/match_up/templates/controls.j2 b/src/match_up/templates/controls.j2 new file mode 100644 index 0000000..6ba724a --- /dev/null +++ b/src/match_up/templates/controls.j2 @@ -0,0 +1,56 @@ +{% from "macros.j2" import court %} +
+
+ {% for key, value in courts.items() %} + {{ court(key, value) }} + {% endfor %} +
+
+
+
+
+
+ +
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+
+ +
+
+ +
+
\ No newline at end of file diff --git a/src/match_up/templates/games.j2 b/src/match_up/templates/games.j2 new file mode 100644 index 0000000..d5afef1 --- /dev/null +++ b/src/match_up/templates/games.j2 @@ -0,0 +1,21 @@ + + + + + + + + + + +{% for game in games %} + + + +{% endfor %} + +
{{ title }}
Court Team 1 Team 2
{{ game.court }}{{ game.team1.player1 }} + {{ game.team1.player2 }} + {{ game.team2.player1 }} + {{ game.team2.player2 }} +
\ No newline at end of file diff --git a/src/match_up/templates/index.j2 b/src/match_up/templates/index.j2 new file mode 100644 index 0000000..832dbfb --- /dev/null +++ b/src/match_up/templates/index.j2 @@ -0,0 +1,13 @@ +{% from "macros.j2" import header, footer, navbar %} + + + {{ header() }} + +
+ {{ navbar() }} +
+
+ {{ footer() }} +
+ + diff --git a/src/match_up/templates/macros.j2 b/src/match_up/templates/macros.j2 new file mode 100644 index 0000000..8d05bb0 --- /dev/null +++ b/src/match_up/templates/macros.j2 @@ -0,0 +1,67 @@ +{% macro court(id, status) -%} + +{%- endmacro %} + +{% macro player(id, status, name) -%} + +{%- endmacro %} + +{% macro guests(count) -%} +
+ +
+{%- endmacro %} + +{% macro timer(mins, secs) -%} +
+

⏲️ {{mins}}:{{secs}}

+
+{%- endmacro %} + +{% macro header() -%} + + + + Match Up! + + + + + +{%- endmacro %} + +{% macro footer() -%} +
Made by Karan using Flask, HTMX and Bulma
+{%- endmacro %} + +{% macro navbar() -%} + +{%- endmacro %} \ No newline at end of file diff --git a/src/match_up/templates/players.j2 b/src/match_up/templates/players.j2 new file mode 100644 index 0000000..ae6afe0 --- /dev/null +++ b/src/match_up/templates/players.j2 @@ -0,0 +1,17 @@ +{% from "macros.j2" import header, navbar, footer, player %} + + + {{ header() }} + +
+ {{ navbar() }} +
+
+ {% for id, value in players.items() %} +
{{ player(id, value.status, value.name) }}
+ {% endfor %} +
+ {{ footer() }} +
+ + \ No newline at end of file -- cgit v1.3.1 From 5b01707a04c362ced66428bef8e0234176d212d9 Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Fri, 8 Nov 2024 17:30:19 +0100 Subject: Added the changes to the templates to pass the url_for function --- pyproject.toml | 4 ++-- src/match_up/__init__.py | 20 +++++++++++++------- src/match_up/templates/index.j2 | 4 ++-- src/match_up/templates/macros.j2 | 4 ++-- src/match_up/templates/players.j2 | 4 ++-- 5 files changed, 21 insertions(+), 15 deletions(-) (limited to 'src/match_up/templates') 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/", 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 %} - {{ header() }} + {{ header(url_for) }}
- {{ navbar() }} + {{ navbar(url_for) }}
{{ 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 @@ {%- endmacro %} -{% macro header() -%} +{% macro header(url_for) -%} @@ -38,7 +38,7 @@
Made by Karan using Flask, HTMX and Bulma
{%- endmacro %} -{% macro navbar() -%} +{% macro navbar(url_for) -%}