diff --git a/app.py b/app.py index 7652379..64d6bc7 100644 --- a/app.py +++ b/app.py @@ -4,11 +4,13 @@ import jinja_partials from decorators import validate_person, validate_topset, validate_workout from db import DataBase from utils import get_people_and_exercise_rep_maxes +from flask_htmx import HTMX app = Flask(__name__) app.config.from_pyfile('config.py') jinja_partials.register_extensions(app) db = DataBase(app) +htmx = HTMX(app) @ app.route("/") @@ -16,7 +18,10 @@ def dashboard(): all_topsets = db.get_all_topsets() people_and_exercise_rep_maxes = get_people_and_exercise_rep_maxes( all_topsets) - return render_template('index.html', model=people_and_exercise_rep_maxes) + if htmx: + return render_template('partials/page/dashboard.html', + model=people_and_exercise_rep_maxes), 200, {"HX-Trigger": "updatedPeople"} + return render_template('dashboard.html', model=people_and_exercise_rep_maxes) @ app.route("/person/list", methods=['GET']) @@ -29,10 +34,14 @@ def get_person_list(): @ validate_person def get_person(person_id): person = db.get_person(person_id) + if htmx: + return render_template('partials/page/person.html', + person=person, is_filtered=False), 200, {"HX-Trigger": "updatedPeople"} + return render_template('person.html', person=person) -@app.route("/person//exercise_filter", methods=['POST']) +@ app.route("/person//exercise_filter", methods=['POST']) @ validate_person def filter_exercises_for_person(person_id): selected_exercise_ids = [int(i) @@ -204,6 +213,9 @@ def delete_exercise(exercise_id): 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_template('settings.html', people=people, exercises=exercises) diff --git a/requirements.txt b/requirements.txt index 2055006..039ef45 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ -Flask==2.0.1 +Flask==2.2.2 gunicorn==19.7.1 Jinja2==3.0.1 jinja-partials==0.1.1 -psycopg2-binary==2.9.3 \ No newline at end of file +psycopg2-binary==2.9.3 +flask-htmx==0.2.0 \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 154ddd6..29b366b 100644 --- a/templates/base.html +++ b/templates/base.html @@ -75,8 +75,8 @@
- + @@ -92,8 +92,8 @@
- + @@ -110,7 +110,7 @@
-
+
{% block content %} {% endblock %}
diff --git a/templates/dashboard.html b/templates/dashboard.html new file mode 100644 index 0000000..9c9e5a1 --- /dev/null +++ b/templates/dashboard.html @@ -0,0 +1,8 @@ +{% extends 'base.html' %} + +{% block content %} + +{{ render_partial('partials/page/dashboard.html', +people=people, exercises=exercises) }} + +{% endblock %} \ No newline at end of file diff --git a/templates/index.html b/templates/partials/page/dashboard.html similarity index 96% rename from templates/index.html rename to templates/partials/page/dashboard.html index 33a89f5..b76810d 100644 --- a/templates/index.html +++ b/templates/partials/page/dashboard.html @@ -1,7 +1,3 @@ -{% extends 'base.html' %} - -{% block content %} -