adds delete feature for last pitstop
Adds the possibility to delete the latest pitstop after a confirmation page.
This commit is contained in:
parent
6d26ceeae8
commit
6f7716abc6
@ -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/<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'])
|
||||
@login_required
|
||||
def get_pit_stops():
|
||||
|
@ -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!')
|
||||
|
35
app/rollerverbrauch/templates/deletePitstopForm.html
Normal file
35
app/rollerverbrauch/templates/deletePitstopForm.html
Normal 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 %}
|
@ -58,6 +58,15 @@
|
||||
{{ (pitstop.costs / pitstop.litres) | round(2) }} €/l
|
||||
</td>
|
||||
</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 %}
|
||||
<tr class='pitstop'>
|
||||
<td>
|
||||
|
Loading…
Reference in New Issue
Block a user