From 38d250902bf76b7afd1f8313c7f84e100ade98f5 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sat, 15 Jul 2023 23:27:14 +1000 Subject: [PATCH] Use jinja2_fragments to remove wrapper templates to handle htmx and non-htmx requests(Full or just partial html) --- app.py | 5 +- requirements.txt | 3 +- templates/partials/page/settings.html | 205 ------------------------- templates/settings.html | 207 +++++++++++++++++++++++++- 4 files changed, 210 insertions(+), 210 deletions(-) delete mode 100644 templates/partials/page/settings.html diff --git a/app.py b/app.py index 9d78309..303b467 100644 --- a/app.py +++ b/app.py @@ -2,7 +2,9 @@ from datetime import datetime, date, timedelta from dateutil.relativedelta import relativedelta import os from flask import Flask, render_template, redirect, request, url_for +from jinja2 import Environment, FileSystemLoader, select_autoescape import jinja_partials +from jinja2_fragments import render_block from decorators import validate_person, validate_topset, validate_workout from db import DataBase from utils import flatten, get_date_info, get_people_and_exercise_rep_maxes, convert_str_to_date, get_earliest_and_latest_workout_date, filter_workout_topsets, get_exercise_ids_from_workouts, first_and_last_visible_days_in_month @@ -327,8 +329,7 @@ def settings(): people = db.get_people() exercises = db.get_exercises() if htmx: - return render_template('partials/page/settings.html', - people=people, exercises=exercises), 200, {"HX-Trigger": "updatedPeople"} + return render_block(app.jinja_env, "settings.html", "content", people=people, exercises=exercises), 200, {"HX-Trigger": "updatedPeople"} return render_template('settings.html', people=people, exercises=exercises) diff --git a/requirements.txt b/requirements.txt index ac809cc..0d16f88 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ jinja-partials==0.1.1 psycopg2-binary==2.9.3 flask-htmx==0.2.0 python-dateutil==2.8.2 -minify-html==0.10.3 \ No newline at end of file +minify-html==0.10.3 +jinja2-fragments==0.3.0 \ No newline at end of file diff --git a/templates/partials/page/settings.html b/templates/partials/page/settings.html deleted file mode 100644 index 0365ed3..0000000 --- a/templates/partials/page/settings.html +++ /dev/null @@ -1,205 +0,0 @@ -
-
-
-
-

Users

-
-
- -
-
-
-
- - - - - - - - - {% for p in people %} - {{ render_partial('partials/person.html', person_id=p['PersonId'], - name=p['Name'])}} - {% endfor %} - - -
- Name - -
-
- -
- - -
-
-
-
-
-
- -
-
-
- - -
- -
- -
-
-
-
- -
-
-
-

Exercises

-
-
- -
-
-
-
- - - - - - - - - {% for e in exercises %} - {{ render_partial('partials/exercise.html', exercise_id=e['ExerciseId'], - name=e['Name'])}} - {% endfor %} - - -
- Name - -
-
- -
- - -
-
-
-
-
-
- -
-
-
- - -
- -
- -
-
-
- -
-
\ No newline at end of file diff --git a/templates/settings.html b/templates/settings.html index e104e97..a5712fd 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -2,7 +2,210 @@ {% block content %} -{{ render_partial('partials/page/settings.html', -people=people, exercises=exercises) }} +
+
+
+
+

Users

+
+
+ +
+
+
+
+ + + + + + + + + {% for p in people %} + {{ render_partial('partials/person.html', person_id=p['PersonId'], + name=p['Name'])}} + {% endfor %} + + +
+ Name + +
+
+ +
+ + +
+
+
+
+
+
+ +
+
+
+ + +
+ +
+ +
+
+
+
+ +
+
+
+

Exercises

+
+
+ +
+
+
+
+ + + + + + + + + {% for e in exercises %} + {{ render_partial('partials/exercise.html', exercise_id=e['ExerciseId'], + name=e['Name'])}} + {% endfor %} + + +
+ Name + +
+
+ +
+ + +
+
+
+
+
+
+ +
+
+
+ + +
+ +
+ +
+
+
+ +
+
{% endblock %} \ No newline at end of file