From b26a1905ad07012e1ec750f4f642668a2ece1a34 Mon Sep 17 00:00:00 2001 From: Stef Date: Thu, 5 Jun 2025 12:02:13 +0200 Subject: [PATCH 1/3] Fixed flash msgs on add page --- application/dashboard/templates/add.html | 30 ------------------------ application/dashboard/views.py | 26 ++++++-------------- 2 files changed, 7 insertions(+), 49 deletions(-) diff --git a/application/dashboard/templates/add.html b/application/dashboard/templates/add.html index d58cd74..39330db 100644 --- a/application/dashboard/templates/add.html +++ b/application/dashboard/templates/add.html @@ -55,34 +55,4 @@ - - {% endblock %} \ No newline at end of file diff --git a/application/dashboard/views.py b/application/dashboard/views.py index 6ee69f5..a7ecfee 100644 --- a/application/dashboard/views.py +++ b/application/dashboard/views.py @@ -4,12 +4,14 @@ from flask import ( request, jsonify, flash, - send_from_directory, + send_file, ) from application.dashboard.models import AllowedPlate, LoggedItem from application import db +import application from application.dashboard.forms import npForm from flask_login import login_required +from io import BytesIO dash_blueprint = Blueprint("dash", __name__, template_folder="templates") @@ -27,7 +29,6 @@ def dashboard(): @dash_blueprint.route("/add", methods=["GET", "POST"]) @login_required def add(): - Plates = AllowedPlate.query.all() form = npForm() if form.validate_on_submit(): @@ -41,18 +42,8 @@ def add(): db.session.add(ap) db.session.commit() flash("Numberplate succesfully added") - - # Update the list on the page with JavaScript - if request.headers.get("X-Requested-With") == "XMLHttpRequest": - plates = AllowedPlate.query.order_by(AllowedPlate.id).all() - return jsonify( - { - "plates": [ - {"id": p.id, "plate": p.plate} for p in plates - ] - } - ) # form wasn't valid + Plates = AllowedPlate.query.all() return render_template( "add.html", form=npForm(formdata=None), plates=Plates ) @@ -67,9 +58,6 @@ def live(): @dash_blueprint.route("/live_image", methods=["GET"]) @login_required def live_image(): - return send_from_directory( - "static/live", - "feed.png", - as_attachment=False, - conditional=True, - ) + image_copy = BytesIO(application.last_image.getvalue()) + image_copy.seek(0) + return send_file(image_copy, mimetype="image/jpeg") From 5a9f20b0b8006049dbb29ae871044a652ef146a3 Mon Sep 17 00:00:00 2001 From: DaanoGames Date: Thu, 5 Jun 2025 12:08:18 +0200 Subject: [PATCH 2/3] added flash message for logout --- application/auth/views.py | 1 + application/dashboard/templates/flash.html | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 application/dashboard/templates/flash.html diff --git a/application/auth/views.py b/application/auth/views.py index 44db250..0b9879a 100644 --- a/application/auth/views.py +++ b/application/auth/views.py @@ -29,6 +29,7 @@ def login(): @login_required def logout(): logout_user() + flash("Succesfully logged out") return redirect("/") diff --git a/application/dashboard/templates/flash.html b/application/dashboard/templates/flash.html new file mode 100644 index 0000000..7fa451b --- /dev/null +++ b/application/dashboard/templates/flash.html @@ -0,0 +1,18 @@ + + + + + + +
+ {% for message in get_flashed_messages() %} + + {% endfor %} +
\ No newline at end of file From b621ca484dab05a45977c7a11694e9a743ef7ded Mon Sep 17 00:00:00 2001 From: DaanoGames Date: Thu, 5 Jun 2025 23:16:18 +0200 Subject: [PATCH 3/3] added flash message on login page --- application/auth/templates/login.html | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/application/auth/templates/login.html b/application/auth/templates/login.html index 1f6f76f..9321ce2 100644 --- a/application/auth/templates/login.html +++ b/application/auth/templates/login.html @@ -80,6 +80,24 @@ + + + + + + +
+ {% for message in get_flashed_messages() %} + + {% endfor %} +
\ No newline at end of file