diff --git a/application/dashboard/forms.py b/application/dashboard/forms.py index 9f7adfd..39f6cdf 100644 --- a/application/dashboard/forms.py +++ b/application/dashboard/forms.py @@ -4,5 +4,6 @@ from wtforms import StringField, SubmitField class npForm(FlaskForm): - numberplate = StringField("add a numberplate", validators=[DataRequired()]) - submit = SubmitField("Submit") + numberplate = StringField('Insert plate here:', validators=[DataRequired()]) + submit = SubmitField('Submit') + diff --git a/application/dashboard/templates/dashboard.html b/application/dashboard/templates/dashboard.html index bba7209..8145f84 100644 --- a/application/dashboard/templates/dashboard.html +++ b/application/dashboard/templates/dashboard.html @@ -10,64 +10,69 @@ -
-
-
-
Logs
-
- - - - - - - - - - {% for log in logs %} - - - - - - {% endfor %} - -
TimeNumberplateGate Status
{{ log.dateLogged.strftime('%H:%M:%S') }}{{ log.plate }} - - {{ log.allowed }} - -
-
+
+
+
+
Logs
+
+ + + + + + + + + + {% for log in logs %} + + + + + + {% endfor %} + +
TimeNumberplateGate Status
{{ log.dateLogged.strftime('%H:%M:%S') }}{{ log.plate }} + + {{ log.allowed }} + +
+
-
-
-
-
Numberplates
-
- - - - - - - - - {% for plate in plates %} - - - - - {% endfor %} - -
IDNumberplate
{{ plate.id }}{{ plate.plate }}
-
+
+
+
+
Numberplates
+
+ + + + + + + + + {% for plate in plates %} + + + + + + {% endfor %} + +
IDNumberplate
{{ plate.id }}{{ plate.plate }} + Edit +
+ +
+
+
diff --git a/application/dashboard/templates/edit.html b/application/dashboard/templates/edit.html new file mode 100644 index 0000000..0354946 --- /dev/null +++ b/application/dashboard/templates/edit.html @@ -0,0 +1,110 @@ +{%extends 'base.html' %} +{% block content %} + +
+
+

Numberplate

+
+
+
+
+
+
+
+
+
Edit numberplate
+
+
+ {{ form.hidden_tag() }} +
+ {{ form.numberplate.label }} {{ form.numberplate(class="form-input") }} +
+
+ {{ form.submit(class="submit-btn") }} +
+
+
+
+
+
+ + + + + +{% endblock %} \ No newline at end of file diff --git a/application/dashboard/views.py b/application/dashboard/views.py index 6ee69f5..fb0c594 100644 --- a/application/dashboard/views.py +++ b/application/dashboard/views.py @@ -5,6 +5,8 @@ from flask import ( jsonify, flash, send_from_directory, + redirect, + url_for ) from application.dashboard.models import AllowedPlate, LoggedItem from application import db @@ -15,7 +17,7 @@ dash_blueprint = Blueprint("dash", __name__, template_folder="templates") @dash_blueprint.route("/dashboard") -@login_required +#@login_required def dashboard(): Plates = AllowedPlate.query.all() logs = ( @@ -25,7 +27,7 @@ def dashboard(): @dash_blueprint.route("/add", methods=["GET", "POST"]) -@login_required +#@login_required def add(): Plates = AllowedPlate.query.all() form = npForm() @@ -73,3 +75,36 @@ def live_image(): as_attachment=False, conditional=True, ) + + +@dash_blueprint.route('/logs', methods=['GET', 'POST']) +#@login_required +def logs(): + form = LoggedItem.query.all() + return render_template("logs.html", form=form) + +@dash_blueprint.route("/edit/",methods=["GET", "POST"]) +#login_required +def edit(plate: str): + print(plate) + editnp = AllowedPlate.query.filter_by(plate=plate).first_or_404() + form = npForm() + if form.validate_on_submit(): + commit = False + if editnp.plate != form.numberplate.data: + editnp.plate = form.numberplate.data + commit = True + if commit: + db.session.commit() + return redirect(url_for("dash.dashboard")) + form.numberplate.data = editnp.plate + return render_template("edit.html",form=form) + +@dash_blueprint.route("/delete/", methods=["POST"]) +#@login_required +def delete_plate(plate: str): + plate_obj = AllowedPlate.query.filter_by(plate=plate).first_or_404() + db.session.delete(plate_obj) + db.session.commit() + flash("Numberplate deleted successfully.") + return redirect(url_for("dash.dashboard")) \ No newline at end of file