diff --git a/application/auth/views.py b/application/auth/views.py
index 8c34db8..44db250 100644
--- a/application/auth/views.py
+++ b/application/auth/views.py
@@ -1,4 +1,4 @@
-from flask import Blueprint, redirect, url_for, render_template
+from flask import Blueprint, redirect, url_for, render_template, flash
from application.auth.forms import login_form
from application.auth.models import User
from flask_login import login_user, login_required, logout_user
@@ -20,6 +20,7 @@ def login():
if user and user.check_password(password=password):
login_user(user)
+ flash("Succesfully logged in")
return redirect(url_for("dash.dashboard"))
return render_template("login.html", form=loginForm)
diff --git a/application/dashboard/templates/base.html b/application/dashboard/templates/base.html
index b03419c..4c2eef4 100644
--- a/application/dashboard/templates/base.html
+++ b/application/dashboard/templates/base.html
@@ -97,6 +97,24 @@
+
+
+
+ {% for message in get_flashed_messages() %}
+
+
+ {{message}}
+
+
+ {% endfor %}
+
{%block content%}
diff --git a/application/dashboard/views.py b/application/dashboard/views.py
index ee4c48c..34725ae 100644
--- a/application/dashboard/views.py
+++ b/application/dashboard/views.py
@@ -1,4 +1,4 @@
-from flask import Blueprint, render_template, request, jsonify
+from flask import Blueprint, render_template, request, jsonify, flash
from application.dashboard.models import AllowedPlate, LoggedItem
from application import db
from application.dashboard.forms import npForm
@@ -24,21 +24,31 @@ def add():
form = npForm()
if form.validate_on_submit():
- if form.numberplate.data:
- ap = AllowedPlate(plate=form.numberplate.data)
- db.session.add(ap)
- db.session.commit()
+ plate = form.numberplate.data
+ print("test")
+ if AllowedPlate.query.filter_by(plate=plate).first():
+ print("test1")
+ flash("Numberplate is already registered")
+ return render_template(
+ "dashboard.html",
+ form=npForm(formdata=None),
+ feedback="Numberplate is already registered",
+ )
+ ap = AllowedPlate(plate=plate)
+ db.session.add(ap)
+ db.session.commit()
+ print("test2")
+ flash("Numberplate succesfully added")
- # Update the list on the page with JavaScript
- 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)
+ # Update the list on the page with JavaScript
+ 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=npForm(formdata=None), plates=Plates)