mirror of
https://github.com/StefBuwalda/ProjectIOT.git
synced 2025-10-30 19:29:57 +00:00
43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
from flask import Blueprint, render_template, request, jsonify
|
|
from application.dashboard.models import AllowedPlate, LoggedItem
|
|
from application import db
|
|
from application.dashboard.forms import npForm
|
|
|
|
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():
|
|
Plates = AllowedPlate.query.all()
|
|
form = npForm()
|
|
|
|
if form.validate_on_submit():
|
|
if form.numberplate.data:
|
|
ap = AllowedPlate(plate=form.numberplate.data)
|
|
db.session.add(ap)
|
|
db.session.commit()
|
|
|
|
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
|
|
]
|
|
}
|
|
)
|
|
|
|
Plates = AllowedPlate.query.order_by(AllowedPlate.id).all()
|
|
return render_template("add.html", form=form, plates=Plates)
|