mirror of
				https://github.com/StefBuwalda/ProjectIOT.git
				synced 2025-10-30 11:19: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, |     send_from_directory, | ||||||
|     redirect, |     redirect, | ||||||
|     url_for |     url_for | ||||||
|     send_file, | #    send_file, | ||||||
| ) | ) | ||||||
| from application.dashboard.models import AllowedPlate, LoggedItem | from application.dashboard.models import AllowedPlate, LoggedItem | ||||||
| from application import db | from application import db | ||||||
| @@ -83,11 +83,21 @@ def edit(plate: str): | |||||||
|     form = npForm() |     form = npForm() | ||||||
|     if form.validate_on_submit(): |     if form.validate_on_submit(): | ||||||
|         commit = False |         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: |         if editnp.plate != form.numberplate.data: | ||||||
|             editnp.plate = form.numberplate.data |             editnp.plate = form.numberplate.data | ||||||
|             commit = True |             commit = True | ||||||
|         if commit: |         if commit: | ||||||
|             db.session.commit() |             db.session.commit() | ||||||
|  |             flash("Numberplate edited succesfully") | ||||||
|             return redirect(url_for("dash.dashboard")) |             return redirect(url_for("dash.dashboard")) | ||||||
|     form.numberplate.data = editnp.plate |     form.numberplate.data = editnp.plate | ||||||
|     return render_template("edit.html",form=form) |     return render_template("edit.html",form=form) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 DaanoGames
					DaanoGames