Edit en Delete functie toegevoegd

This commit is contained in:
gavinvanderbij
2025-06-04 15:13:53 +02:00
parent 75b19f2e1b
commit 0c096891ea
4 changed files with 206 additions and 55 deletions

View File

@@ -5,6 +5,8 @@ from flask import (
jsonify,
flash,
send_from_directory,
redirect,
url_for
)
from application.dashboard.models import AllowedPlate, LoggedItem
from application import db
@@ -15,7 +17,7 @@ dash_blueprint = Blueprint("dash", __name__, template_folder="templates")
@dash_blueprint.route("/dashboard")
@login_required
#@login_required
def dashboard():
Plates = AllowedPlate.query.all()
logs = (
@@ -25,7 +27,7 @@ def dashboard():
@dash_blueprint.route("/add", methods=["GET", "POST"])
@login_required
#@login_required
def add():
Plates = AllowedPlate.query.all()
form = npForm()
@@ -73,3 +75,36 @@ def live_image():
as_attachment=False,
conditional=True,
)
@dash_blueprint.route('/logs', methods=['GET', 'POST'])
#@login_required
def logs():
form = LoggedItem.query.all()
return render_template("logs.html", form=form)
@dash_blueprint.route("/edit/<string:plate>",methods=["GET", "POST"])
#login_required
def edit(plate: str):
print(plate)
editnp = AllowedPlate.query.filter_by(plate=plate).first_or_404()
form = npForm()
if form.validate_on_submit():
commit = False
if editnp.plate != form.numberplate.data:
editnp.plate = form.numberplate.data
commit = True
if commit:
db.session.commit()
return redirect(url_for("dash.dashboard"))
form.numberplate.data = editnp.plate
return render_template("edit.html",form=form)
@dash_blueprint.route("/delete/<string:plate>", methods=["POST"])
#@login_required
def delete_plate(plate: str):
plate_obj = AllowedPlate.query.filter_by(plate=plate).first_or_404()
db.session.delete(plate_obj)
db.session.commit()
flash("Numberplate deleted successfully.")
return redirect(url_for("dash.dashboard"))