mirror of
https://github.com/StefBuwalda/ProjectIOT.git
synced 2025-10-29 18:59:57 +00:00
added checks for edit and flash messages
This commit is contained in:
@@ -7,7 +7,7 @@ from flask import (
|
||||
send_from_directory,
|
||||
redirect,
|
||||
url_for
|
||||
send_file,
|
||||
# send_file,
|
||||
)
|
||||
from application.dashboard.models import AllowedPlate, LoggedItem
|
||||
from application import db
|
||||
@@ -83,11 +83,21 @@ def edit(plate: str):
|
||||
form = npForm()
|
||||
if form.validate_on_submit():
|
||||
commit = False
|
||||
plate = form.numberplate.data
|
||||
if plate: # To prevent red lines in VSCode
|
||||
# Check if number plate already exists
|
||||
if editnp.plate == form.numberplate.data:
|
||||
flash("Numberplate has not been changed")
|
||||
return redirect(url_for("dash.dashboard"))
|
||||
if AllowedPlate.query.filter_by(plate=plate).first():
|
||||
flash("Numberplate is already registered")
|
||||
return redirect(url_for("dash.dashboard"))
|
||||
if editnp.plate != form.numberplate.data:
|
||||
editnp.plate = form.numberplate.data
|
||||
commit = True
|
||||
if commit:
|
||||
db.session.commit()
|
||||
flash("Numberplate edited succesfully")
|
||||
return redirect(url_for("dash.dashboard"))
|
||||
form.numberplate.data = editnp.plate
|
||||
return render_template("edit.html",form=form)
|
||||
|
||||
Reference in New Issue
Block a user