From 8be441bab9a64431c0a24aeb338c9a3feed89bdd Mon Sep 17 00:00:00 2001 From: paulmart-n Date: Fri, 5 Apr 2024 11:22:14 +0200 Subject: [PATCH] init turbo --- init.py | 6 +++-- routing.py | 18 +++++++++++--- templates/index.html | 49 ++++++++++++++++++++------------------- templates/login.html | 4 ++++ templates/noten-list.html | 21 +++++++++++++++++ templates/noten.html | 26 ++++----------------- 6 files changed, 74 insertions(+), 50 deletions(-) create mode 100644 templates/noten-list.html diff --git a/init.py b/init.py index 9d67306..13b4f38 100644 --- a/init.py +++ b/init.py @@ -5,6 +5,7 @@ from flask_talisman import Talisman from get_mysql import get_mysql import atexit from flask_apscheduler import APScheduler +from turbo_flask import Turbo def create(): @@ -13,6 +14,7 @@ def create(): :return app: """ app = Flask(__name__) + turbo.init_app(app) dbpw = get_mysql()[1] dbun = get_mysql()[0] @@ -70,10 +72,10 @@ class Meals(db.Model): scheduler = APScheduler() +turbo = Turbo() app = create() def_src = ["*.paulmartin.cloud", '\'self\''] -Talisman(app, content_security_policy={"default-src": def_src, "script-src": def_src # + ["'unsafe-inline'"] - }) +# Talisman(app, content_security_policy={"default-src": def_src, "script-src": def_src # + ["'unsafe-inline'"]}) scheduler.init_app(app) scheduler.start() scheduler.api_enabled = True diff --git a/routing.py b/routing.py index 4cde145..44b91d3 100644 --- a/routing.py +++ b/routing.py @@ -23,10 +23,14 @@ def index(): Leitet den normalen Website-Aufruf zum Login weiter. :return HTML: """ - return redirect(url_for("login")) + if current_user.is_authenticated: + return welcome() + else: + return login() -@app.route("/dashboard") + +@app.route("/dashboard", methods=["GET", "POST"]) @login_required def welcome(): """ @@ -46,7 +50,15 @@ def welcome(): else: t = "hidden" p = "" - return render_template('dashboard.html', kurs=kurs, name=name, theorie=t, praxis=p) + if turbo.can_stream(): + print ("Streaming...") + return turbo.stream([ + turbo.update( + render_template('dashboard.html', kurs=kurs, name=name, theorie=t, praxis=p), target="content") + ]) + else: + print ("Not streaming!") + return render_template('dashboard.html', kurs=kurs, name=name, theorie=t, praxis=p) @app.route("/theorie/noten") diff --git a/templates/index.html b/templates/index.html index 5e41350..d7c18fd 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,37 +5,38 @@ + {{ turbo() }} {% block head %} {% endblock %} -
-{% block content %} -{% endblock %} -
+ +
+
+ {% block content %} + {% endblock %} +
+
+
diff --git a/templates/login.html b/templates/login.html index 7dd1062..6fd1ee0 100644 --- a/templates/login.html +++ b/templates/login.html @@ -1,4 +1,8 @@ {% extends "index.html" %} +{% block logout %} + hidden +{% endblock %} + {% block content %}

Einloggen

diff --git a/templates/noten-list.html b/templates/noten-list.html new file mode 100644 index 0000000..eb71912 --- /dev/null +++ b/templates/noten-list.html @@ -0,0 +1,21 @@ +{% for i in range (semester|length) %} + {% if semester[i][1]==sel %} +

Deine Noten im {{ semester[i][0] }}

+ {% endif %} +{% endfor %} +
+
+{% for i in noten %} + {% if i[1]|length == 1 %} + {% if i[1][0][0].isnumeric() or i[1][0][-1].isalpha()%} +

{{ i[0][0] }}: {{ i[1][0] }} (Credits: {{ i[2][0] }})

+ {% else %} +

{{ i[0][0] }}: {{ i[1][0][-3:] }} (Credits: {{ i[2][0] }})

+ {% endif %} + {% else %} +

{{ i[0][0] }} (Credits: {{ i[2][0] }}):

+ {% for e in i[1] %} +

      {{ e }}

+ {% endfor %} + {% endif %} +{% endfor %} \ No newline at end of file diff --git a/templates/noten.html b/templates/noten.html index bc67c81..05a98b8 100644 --- a/templates/noten.html +++ b/templates/noten.html @@ -4,27 +4,11 @@ {% endblock %} {% block content %} - {% for i in range (semester|length) %} - {% if semester[i][1]==sel %} -

Deine Noten im {{ semester[i][0] }}

- {% endif %} - {% endfor %} -
-
- {% for i in noten %} - {% if i[1]|length == 1 %} - {% if i[1][0][0].isnumeric() or i[1][0][-1].isalpha()%} -

{{ i[0][0] }}: {{ i[1][0] }} (Credits: {{ i[2][0] }})

- {% else %} -

{{ i[0][0] }}: {{ i[1][0][-3:] }} (Credits: {{ i[2][0] }})

- {% endif %} - {% else %} -

{{ i[0][0] }} (Credits: {{ i[2][0] }}):

- {% for e in i[1] %} -

      {{ e }}

- {% endfor %} - {% endif %} - {% endfor %} + +
+ {% include "noten-list.html" %} +
+