mirror of
https://github.com/StefBuwalda/ProjectIOT.git
synced 2025-10-29 18:59:57 +00:00
no duplicate entries and added flash messages
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -97,6 +97,24 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="d-none">
|
||||
<symbol id="check-circle-fill" viewBox="0 0 16 16">
|
||||
<path
|
||||
d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z" />
|
||||
</symbol>
|
||||
</svg>
|
||||
|
||||
<div class="position-fixed w-25 bottom-0" style="z-index: 1050;">
|
||||
{% for message in get_flashed_messages() %}
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
<svg class="bi flex-shrink-0 me-2" width="15" height="15" role="img" aria-label="Success:">
|
||||
<use xlink:href="#check-circle-fill" />
|
||||
</svg>
|
||||
{{message}}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{%block content%}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user