From 6f7716abc64173e05e62a66e442f6e9d55d6c381 Mon Sep 17 00:00:00 2001 From: Joachim Lusiardi Date: Wed, 22 Jun 2016 22:48:27 +0200 Subject: [PATCH] adds delete feature for last pitstop Adds the possibility to delete the latest pitstop after a confirmation page. --- app/rollerverbrauch/__init__.py | 23 +++++++++++- app/rollerverbrauch/forms.py | 4 +++ .../templates/deletePitstopForm.html | 35 +++++++++++++++++++ app/rollerverbrauch/templates/pitstops.html | 9 +++++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 app/rollerverbrauch/templates/deletePitstopForm.html diff --git a/app/rollerverbrauch/__init__.py b/app/rollerverbrauch/__init__.py index b37ac1c..54670c0 100644 --- a/app/rollerverbrauch/__init__.py +++ b/app/rollerverbrauch/__init__.py @@ -29,7 +29,8 @@ from rollerverbrauch.forms import \ EditVehicleForm, \ DeleteVehicleForm, \ SelectVehicleForm, \ - DeleteAccountForm + DeleteAccountForm, \ + DeletePitStopForm from rollerverbrauch.entities import \ User, \ @@ -208,6 +209,26 @@ def create_pit_stop_form(vid): return render_template('newPitStopForm.html', form=form, vehicle=vehicle, messages = messages) +@app.route('/pitstops/delete/', methods=['GET', 'POST']) +@login_required +def delete_pit_stop_form(pid): + pitstop = Pitstop.query.filter(Pitstop.id == pid).first() + if pitstop is None: + return redirect(url_for('get_pit_stops')) + vehicle = Vehicle.query.filter(Vehicle.id == pitstop.vehicle_id).first() + if vehicle not in current_user.vehicles: + return redirect(url_for('get_pit_stops')) + + form = DeletePitStopForm() + if form.validate_on_submit(): + db.session.delete(pitstop) + db.session.commit() + tools.db_log_delete(pitstop) + return redirect(url_for('get_pit_stops', _anchor='v' + str(vehicle.id))) + + return render_template('deletePitstopForm.html', form=form, pitstop=pitstop ) + + @app.route('/pitstops', methods=['GET']) @login_required def get_pit_stops(): diff --git a/app/rollerverbrauch/forms.py b/app/rollerverbrauch/forms.py index 560de7b..520144e 100644 --- a/app/rollerverbrauch/forms.py +++ b/app/rollerverbrauch/forms.py @@ -54,3 +54,7 @@ class DeleteVehicleForm(Form): class DeleteAccountForm(Form): submit = SubmitField(label='Really delete my account!') + + +class DeletePitStopForm(Form): + submit = SubmitField(label='Really delete this pitstop!') diff --git a/app/rollerverbrauch/templates/deletePitstopForm.html b/app/rollerverbrauch/templates/deletePitstopForm.html new file mode 100644 index 0000000..fa14203 --- /dev/null +++ b/app/rollerverbrauch/templates/deletePitstopForm.html @@ -0,0 +1,35 @@ +{% extends 'layout.html' %} + +{% block body %} +
+
+
+
+

Delete pitstop?

+ + + + + + + + + + + + + + + + + +
Date of Pitstop{{ pitstop.date }}
Odometer{{ pitstop.odometer }} km
Litres{{ pitstop.litres }} l
Costs (overall){{ pitstop.costs }} €
+
+ {{ form.hidden_tag() }} + {{ render_field_with_errors(form.submit) }} +
+
+
+
+
+{% endblock %} diff --git a/app/rollerverbrauch/templates/pitstops.html b/app/rollerverbrauch/templates/pitstops.html index 157df6e..6d637df 100644 --- a/app/rollerverbrauch/templates/pitstops.html +++ b/app/rollerverbrauch/templates/pitstops.html @@ -58,6 +58,15 @@ {{ (pitstop.costs / pitstop.litres) | round(2) }} €/l + {% if loop.first %} + + + + delete + + + + {% endif %} {% else %}