adds delete feature for last pitstop

Adds the possibility to delete the latest pitstop after a
confirmation page.
This commit is contained in:
Joachim Lusiardi 2016-06-22 22:48:27 +02:00
parent 6d26ceeae8
commit 6f7716abc6
4 changed files with 70 additions and 1 deletions

View File

@ -29,7 +29,8 @@ from rollerverbrauch.forms import \
EditVehicleForm, \ EditVehicleForm, \
DeleteVehicleForm, \ DeleteVehicleForm, \
SelectVehicleForm, \ SelectVehicleForm, \
DeleteAccountForm DeleteAccountForm, \
DeletePitStopForm
from rollerverbrauch.entities import \ from rollerverbrauch.entities import \
User, \ User, \
@ -208,6 +209,26 @@ def create_pit_stop_form(vid):
return render_template('newPitStopForm.html', form=form, vehicle=vehicle, messages = messages) return render_template('newPitStopForm.html', form=form, vehicle=vehicle, messages = messages)
@app.route('/pitstops/delete/<int:pid>', 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']) @app.route('/pitstops', methods=['GET'])
@login_required @login_required
def get_pit_stops(): def get_pit_stops():

View File

@ -54,3 +54,7 @@ class DeleteVehicleForm(Form):
class DeleteAccountForm(Form): class DeleteAccountForm(Form):
submit = SubmitField(label='Really delete my account!') submit = SubmitField(label='Really delete my account!')
class DeletePitStopForm(Form):
submit = SubmitField(label='Really delete this pitstop!')

View File

@ -0,0 +1,35 @@
{% extends 'layout.html' %}
{% block body %}
<div class='col-md-2' ></div>
<div class='col-md-8'>
<div class='panel panel-default'>
<div class='panel-body'>
<h3>Delete pitstop?</h3>
<table style='width: 100%'>
<tr>
<th style='text-align:right'>Date of Pitstop</th>
<td style='text-align: left'>{{ pitstop.date }}</td>
</tr>
<tr>
<th style='text-align:right'>Odometer</th>
<td style='text-align: left'>{{ pitstop.odometer }} km</td>
</tr>
<tr>
<th style='text-align:right'>Litres</th>
<td style='text-align: left'>{{ pitstop.litres }} l</td>
</tr>
<tr>
<th style='text-align:right'>Costs (overall)</th>
<td style='text-align: left'>{{ pitstop.costs }} €</td>
</tr>
</table>
<form class='form-horizontal' method='POST'>
{{ form.hidden_tag() }}
{{ render_field_with_errors(form.submit) }}
</form>
</div>
</div>
</div>
<div class='col-md-2' ></div>
{% endblock %}

View File

@ -58,6 +58,15 @@
{{ (pitstop.costs / pitstop.litres) | round(2) }} €/l {{ (pitstop.costs / pitstop.litres) | round(2) }} €/l
</td> </td>
</tr> </tr>
{% if loop.first %}
<tr class='pitstop'>
<td colspan='4'>
<a href="{{ url_for('delete_pit_stop_form', pid=pitstop.id) }}" class="btn btn-primary btn-warning ">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> delete
</a>
</td>
</tr>
{% endif %}
{% else %} {% else %}
<tr class='pitstop'> <tr class='pitstop'>
<td> <td>