mirror of
https://github.com/StefBuwalda/ProjectIOT.git
synced 2025-10-30 11:19:57 +00:00
64 lines
1.8 KiB
Python
64 lines
1.8 KiB
Python
from flask import (
|
|
Blueprint,
|
|
render_template,
|
|
request,
|
|
jsonify,
|
|
flash,
|
|
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")
|
|
|
|
|
|
@dash_blueprint.route("/dashboard")
|
|
@login_required
|
|
def dashboard():
|
|
Plates = AllowedPlate.query.all()
|
|
logs = (
|
|
LoggedItem.query.order_by(LoggedItem.dateLogged.desc()).limit(50).all()
|
|
)
|
|
return render_template("dashboard.html", plates=Plates, logs=logs)
|
|
|
|
|
|
@dash_blueprint.route("/add", methods=["GET", "POST"])
|
|
@login_required
|
|
def add():
|
|
form = npForm()
|
|
|
|
if form.validate_on_submit():
|
|
plate = form.numberplate.data
|
|
if plate: # To prevent red lines in VSCode
|
|
# Check if number plate already exists
|
|
if AllowedPlate.query.filter_by(plate=plate).first():
|
|
flash("Numberplate is already registered")
|
|
else: # NP does not exist
|
|
ap = AllowedPlate(plate=plate)
|
|
db.session.add(ap)
|
|
db.session.commit()
|
|
flash("Numberplate succesfully added")
|
|
# form wasn't valid
|
|
Plates = AllowedPlate.query.all()
|
|
return render_template(
|
|
"add.html", form=npForm(formdata=None), plates=Plates
|
|
)
|
|
|
|
|
|
@dash_blueprint.route("/live", methods=["GET"])
|
|
@login_required
|
|
def live():
|
|
return render_template("live.html")
|
|
|
|
|
|
@dash_blueprint.route("/live_image", methods=["GET"])
|
|
@login_required
|
|
def live_image():
|
|
image_copy = BytesIO(application.last_image.getvalue())
|
|
image_copy.seek(0)
|
|
return send_file(image_copy, mimetype="image/jpeg")
|