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")