From a1fa9557eae563aaee58269636d29ffcac9120b0 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sat, 19 Nov 2022 16:36:20 +1100 Subject: [PATCH] Add support for partial views with jinga-partials and refactor stats as partial view --- app.py | 3 ++- requirements.txt | 1 + templates/index.html | 14 +------------- templates/partials/stats.html | 13 +++++++++++++ templates/person.html | 14 +------------- 5 files changed, 18 insertions(+), 27 deletions(-) create mode 100644 templates/partials/stats.html diff --git a/app.py b/app.py index 675f79a..d50631d 100644 --- a/app.py +++ b/app.py @@ -1,12 +1,13 @@ import os from flask import Flask, render_template, redirect, request, url_for +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 app = Flask(__name__) app.config.from_pyfile('config.py') - +jinja_partials.register_extensions(app) db = DataBase(app) diff --git a/requirements.txt b/requirements.txt index c789d7a..2055006 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ Flask==2.0.1 gunicorn==19.7.1 Jinja2==3.0.1 +jinja-partials==0.1.1 psycopg2-binary==2.9.3 \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index a8d494d..3fba52c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -90,18 +90,6 @@ -
- {% for stat in model['Stats'] %} -
-
-
- {{ - stat['Value'] }} -

{{ stat['Text'] }}

-
-
-
- {% endfor %} -
+{{ render_partial('partials/stats.html', stats=model['Stats']) }} {% endblock %} \ No newline at end of file diff --git a/templates/partials/stats.html b/templates/partials/stats.html new file mode 100644 index 0000000..bf93a16 --- /dev/null +++ b/templates/partials/stats.html @@ -0,0 +1,13 @@ +
+ {% for stat in stats%} +
+
+
+ {{ + stat['Value'] }} +

{{ stat['Text'] }}

+
+
+
+ {% endfor %} +
\ No newline at end of file diff --git a/templates/person.html b/templates/person.html index e2d0f0a..ac24fc8 100644 --- a/templates/person.html +++ b/templates/person.html @@ -96,18 +96,6 @@ -
- {% for stat in person['Stats'] %} -
-
-
- {{ - stat['Value'] }} -

{{ stat['Text'] }}

-
-
-
- {% endfor %} -
+{{ render_partial('partials/stats.html', stats=person['Stats']) }} {% endblock %} \ No newline at end of file