aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaran Jayachandra <karan.jayachandra@nxp.com>2024-10-16 23:36:56 +0200
committerKaran Jayachandra <karan.jayachandra@nxp.com>2024-10-16 23:36:56 +0200
commit310c54caffb137af593e710b2437c2639863574d (patch)
tree6d678db08c6d6df65e0e7c7cbe91b5531e6bf6ab
parent156056e9c31468564fb53ca284996a5de41471fb (diff)
Added a few more j2 macros
-rw-r--r--app.py6
-rw-r--r--templates/macros.j212
2 files changed, 16 insertions, 2 deletions
diff --git a/app.py b/app.py
index 22f6767..f145354 100644
--- a/app.py
+++ b/app.py
@@ -23,12 +23,14 @@ def home():
@app.route("/time", methods=["GET"])
def get_time():
mins, secs = rg.timer.get()
- return render_template("time.j2", mins=mins, secs=secs)
+ t = re.from_string('{% from "macros.j2" import timer %}{{timer(mins, secs)}}')
+ return render_template(t, mins=mins, secs=secs)
@app.route("/guests", methods=["GET"])
def get_guests():
- return render_template("guests.j2", guests=rg.players.guests)
+ t = re.from_string('{% from "macros.j2" import guests %}{{guests(count)}}')
+ return render_template(t, count=rg.players.guests)
@app.route("/decrement", methods=["POST"])
diff --git a/templates/macros.j2 b/templates/macros.j2
index b4767be..7117d11 100644
--- a/templates/macros.j2
+++ b/templates/macros.j2
@@ -8,4 +8,16 @@
<button class="button is-medium is-responsive {% if status %}is-success{% else %}is-danger {% endif %}"
hx-post="{{ "/player-toggle/" ~ id}}"
hx-swap="outerHTML"> {{ name }} </button>
+{%- endmacro %}
+
+{% macro guests(count) -%}
+<div class="control" id="guests">
+ <input class="input is-large is-responsive" type="text" style="text-align:center" value="{{ count }} Guests" disabled>
+</div>
+{%- endmacro %}
+
+{% macro timer(mins, secs) -%}
+<div hx-get="/time" hx-swap="outerHTML" hx-trigger="every 1s">
+ <p class="title">Timer: {{mins}}:{{secs}}</p>
+</div>
{%- endmacro %} \ No newline at end of file