1 Commits

Author SHA1 Message Date
8be441bab9 init turbo 2024-04-05 11:22:14 +02:00
6 changed files with 74 additions and 50 deletions

View File

@ -5,6 +5,7 @@ from flask_talisman import Talisman
from get_mysql import get_mysql from get_mysql import get_mysql
import atexit import atexit
from flask_apscheduler import APScheduler from flask_apscheduler import APScheduler
from turbo_flask import Turbo
def create(): def create():
@ -13,6 +14,7 @@ def create():
:return app: :return app:
""" """
app = Flask(__name__) app = Flask(__name__)
turbo.init_app(app)
dbpw = get_mysql()[1] dbpw = get_mysql()[1]
dbun = get_mysql()[0] dbun = get_mysql()[0]
@ -70,10 +72,10 @@ class Meals(db.Model):
scheduler = APScheduler() scheduler = APScheduler()
turbo = Turbo()
app = create() app = create()
def_src = ["*.paulmartin.cloud", '\'self\''] 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.init_app(app)
scheduler.start() scheduler.start()
scheduler.api_enabled = True scheduler.api_enabled = True

View File

@ -23,10 +23,14 @@ def index():
Leitet den normalen Website-Aufruf zum Login weiter. Leitet den normalen Website-Aufruf zum Login weiter.
:return HTML: :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 @login_required
def welcome(): def welcome():
""" """
@ -46,7 +50,15 @@ def welcome():
else: else:
t = "hidden" t = "hidden"
p = "" 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") @app.route("/theorie/noten")

View File

@ -5,37 +5,38 @@
<link rel="stylesheet" type="text/css" href={{ url_for("static", filename="style.css") }}> <link rel="stylesheet" type="text/css" href={{ url_for("static", filename="style.css") }}>
<meta http-equiv="refresh" content="510"> <meta http-equiv="refresh" content="510">
<script async src="https://analytics.paulmartin.cloud/script.js" data-website-id="459fa66e-e255-4393-8e89-ead8b1572d0d"></script> <script async src="https://analytics.paulmartin.cloud/script.js" data-website-id="459fa66e-e255-4393-8e89-ead8b1572d0d"></script>
{{ turbo() }}
{% block head %} {% block head %}
{% endblock %} {% endblock %}
</head> </head>
<body> <body>
<nav> <nav>
<ul> <ul id = "navbar-items">
{% if theorie=="hidden" and praxis=="hidden" %} {% if theorie=="hidden" and praxis=="hidden" %}
<li class="top"><a class="top" href={{ url_for("welcome", sel="theorie") }}>Theorie</a></li> <li class="top"><a class="top" href={{ url_for("index", sel="theorie") }}>Theorie</a></li>
<li class="top"><a class="top" href={{ url_for("welcome", sel="praxis") }}>Praxis</a></li> <li class="top"><a class="top" href={{ url_for("index", sel="praxis") }}>Praxis</a></li>
{% elif theorie == "hidden" %} {% elif theorie == "hidden" %}
<li class="top"><a class="top" href={{ url_for("welcome", sel="theorie") }}>Theorie</a></li> <li class="top"><a class="top" href={{ url_for("index", sel="theorie") }}>Theorie</a></li>
<li class="top selected"><a class="top selected" href={{ url_for("welcome", sel="praxis") }}>Praxis</a></li> <li class="top selected"><a class="top selected" href={{ url_for("index", sel="praxis") }}>Praxis</a></li>
{% else %} {% else %}
<li class="top selected"><a class="top selected" href={{ url_for("welcome", sel="theorie") }}>Theorie</a></li> <li class="top selected"><a class="top selected" href={{ url_for("index", sel="theorie") }}>Theorie</a></li>
<li class="top"><a class="top" href={{ url_for("welcome", sel="praxis") }}>Praxis</a></li> <li class="top"><a class="top" href={{ url_for("index", sel="praxis") }}>Praxis</a></li>
{% endif %}
<li {{ theorie }}><a {% if s == "n" %} class="selected" {% endif %} href={{ url_for("displayNoten") }}>Noten</a></li>
<li {{ theorie }}><a {% if s == "p" %} class="selected" {% endif %} href={{ url_for("displayRapla") }}>Stundenplan</a></li>
<li {{ praxis }}><a {% if s == "t" %} class="selected" {% endif %} href="">To Dos</a></li>
<li><a {% if s == "s" %} class="selected" {% endif %} href={{ url_for("redKurs") }}>Konfiguration</a></li>
{% if request.endpoint %}
{% if request.endpoint[:7] != "login" %}
<li><a class="bottom" href={{ url_for("logout") }}>Log-Out</a></li>
{% endif %} {% endif %}
{% endif %} <li {{ theorie }}><a {% if s == "n" %} class="selected" {% endif %} href={{ url_for("displayNoten") }}>Noten</a></li>
</ul> <li {{ theorie }}><a {% if s == "p" %} class="selected" {% endif %} href={{ url_for("displayRapla") }}>Stundenplan</a></li>
<li {{ praxis }}><a {% if s == "t" %} class="selected" {% endif %} href="">To Dos</a></li>
<li><a {% if s == "s" %} class="selected" {% endif %} href={{ url_for("redKurs") }}>Konfiguration</a></li>
<li {% block logout %}{% endblock %}><a class="bottom" href={{ url_for("logout") }}>Log-Out</a></li>
</ul>
</nav> </nav>
<div class="cs1"> <turbo-frame>
{% block content %} <div class="cs1" id = 'page'>
{% endblock %} <div id="content">
</div> {% block content %}
{% endblock %}
</div>
</div>
</turbo-frame>
</body> </body>
</html> </html>

View File

@ -1,4 +1,8 @@
{% extends "index.html" %} {% extends "index.html" %}
{% block logout %}
hidden
{% endblock %}
{% block content %} {% block content %}
<div class="cs"> <div class="cs">
<h1>Einloggen</h1> <h1>Einloggen</h1>

21
templates/noten-list.html Normal file
View File

@ -0,0 +1,21 @@
{% for i in range (semester|length) %}
{% if semester[i][1]==sel %}
<h1>Deine Noten im {{ semester[i][0] }}</h1>
{% endif %}
{% endfor %}
<br>
<br>
{% for i in noten %}
{% if i[1]|length == 1 %}
{% if i[1][0][0].isnumeric() or i[1][0][-1].isalpha()%}
<h2>{{ i[0][0] }}: {{ i[1][0] }} (Credits: {{ i[2][0] }})</h2>
{% else %}
<h2>{{ i[0][0] }}: {{ i[1][0][-3:] }} (Credits: {{ i[2][0] }})</h2>
{% endif %}
{% else %}
<h2>{{ i[0][0] }} (Credits: {{ i[2][0] }}):</h2>
{% for e in i[1] %}
<h2>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;{{ e }}</h2>
{% endfor %}
{% endif %}
{% endfor %}

View File

@ -4,27 +4,11 @@
<meta http-equiv="Refresh" content="600"> <meta http-equiv="Refresh" content="600">
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{% for i in range (semester|length) %} <turbo-frame>
{% if semester[i][1]==sel %} <div id="noten">
<h1>Deine Noten im {{ semester[i][0] }}</h1> {% include "noten-list.html" %}
{% endif %} </div>
{% endfor %} </turbo-frame>
<br>
<br>
{% for i in noten %}
{% if i[1]|length == 1 %}
{% if i[1][0][0].isnumeric() or i[1][0][-1].isalpha()%}
<h2>{{ i[0][0] }}: {{ i[1][0] }} (Credits: {{ i[2][0] }})</h2>
{% else %}
<h2>{{ i[0][0] }}: {{ i[1][0][-3:] }} (Credits: {{ i[2][0] }})</h2>
{% endif %}
{% else %}
<h2>{{ i[0][0] }} (Credits: {{ i[2][0] }}):</h2>
{% for e in i[1] %}
<h2>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;{{ e }}</h2>
{% endfor %}
{% endif %}
{% endfor %}
<br> <br>
<br> <br>
<form id= "dropdown" method="post" action={{ url_for ("setSemester", next=url_for("displayNoten")) }}> <form id= "dropdown" method="post" action={{ url_for ("setSemester", next=url_for("displayNoten")) }}>