mirror of
https://github.com/StefBuwalda/ProjectIOT.git
synced 2025-10-29 18:59:57 +00:00
Refactor
This commit is contained in:
2
app.py
2
app.py
@@ -2,7 +2,7 @@ from application import app
|
||||
from application.api.views import api_blueprint
|
||||
from application.auth.views import auth_blueprint
|
||||
from application.dashboard.views import dash_blueprint
|
||||
from flask import redirect, url_for, render_template
|
||||
from flask import redirect, url_for
|
||||
|
||||
app.register_blueprint(api_blueprint, url_prefix="/api")
|
||||
app.register_blueprint(auth_blueprint, url_prefix="/auth")
|
||||
|
||||
@@ -7,17 +7,18 @@ from application.dashboard.forms import npForm
|
||||
dash_blueprint = Blueprint("dash", __name__, template_folder="templates")
|
||||
|
||||
|
||||
|
||||
@dash_blueprint.route('/dashboard')
|
||||
#@login_required
|
||||
@dash_blueprint.route("/dashboard")
|
||||
# @login_required
|
||||
def dashboard():
|
||||
Plates = AllowedPlate.query.all()
|
||||
logs = LoggedItem.query.order_by(LoggedItem.dateLogged.desc()).limit(50).all()
|
||||
logs = (
|
||||
LoggedItem.query.order_by(LoggedItem.dateLogged.desc()).limit(50).all()
|
||||
)
|
||||
return render_template("dashboard.html", plates=Plates, logs=logs)
|
||||
|
||||
|
||||
@dash_blueprint.route('/add', methods=['GET', 'POST'])
|
||||
#@login_required
|
||||
@dash_blueprint.route("/add", methods=["GET", "POST"])
|
||||
# @login_required
|
||||
def add():
|
||||
Plates = AllowedPlate.query.all()
|
||||
form = npForm()
|
||||
@@ -28,13 +29,15 @@ def add():
|
||||
db.session.add(ap)
|
||||
db.session.commit()
|
||||
|
||||
if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
|
||||
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]
|
||||
})
|
||||
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user