AT opmaak dashboard

This commit is contained in:
Anh-Thy04
2025-05-23 12:54:42 +02:00
parent 2f7a499c91
commit f77c3c523b
4 changed files with 202 additions and 35 deletions

View File

@@ -1,4 +1,4 @@
from flask import Blueprint, render_template
from flask import Blueprint, render_template, request, jsonify
from flask_login import login_required
from application.dashboard.models import AllowedPlate, LoggedItem
from application import db, app
@@ -11,32 +11,30 @@ dash_blueprint = Blueprint("dash", __name__, template_folder="templates")
@dash_blueprint.route('/dashboard')
#@login_required
def dashboard():
#print("test123")
#with app.app_context():
Plates = AllowedPlate.query.all()
print(Plates)
return render_template("dashboard.html", AllowedPlates = Plates)
recent_logs = LoggedItem.query.order_by(LoggedItem.dateLogged.desc()).limit(50).all()
return render_template("dashboard.html", plates=Plates, recent_logs=recent_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:
print(form.numberplate.data)
ap = AllowedPlate(plate=form.numberplate.data)
db.session.add(ap)
db.session.commit()
# AJAX response
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]
})
# Normal GET or failed POST
Plates = AllowedPlate.query.order_by(AllowedPlate.id).all()
return render_template("add.html", form=form, plates=Plates)
return render_template("add.html", form=form)
@dash_blueprint.route('/logs', methods=['GET', 'POST'])
#@login_required
def logs():
form = LoggedItem.query.all()
return render_template("logs.html", form=form)