fixes display of last pitstops
the display of the last pitstops now is separated by vehicle.
This commit is contained in:
parent
038e255b56
commit
34905921d9
|
@ -95,7 +95,7 @@ def delete_vehicle(vid):
|
||||||
vehicle = Vehicle.query.filter(Vehicle.id == vid).first()
|
vehicle = Vehicle.query.filter(Vehicle.id == vid).first()
|
||||||
|
|
||||||
# prevent deletion of foreign vehicles
|
# prevent deletion of foreign vehicles
|
||||||
if not vehicle in current_user.vehicles:
|
if vehicle not in current_user.vehicles:
|
||||||
return redirect(url_for('get_account_page'))
|
return redirect(url_for('get_account_page'))
|
||||||
|
|
||||||
form = DeleteVehicleForm()
|
form = DeleteVehicleForm()
|
||||||
|
@ -131,7 +131,7 @@ def select_vehicle_for_new_pitstop():
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
vehicle = Vehicle.query.filter(Vehicle.id == form.vehicle.data).first()
|
vehicle = Vehicle.query.filter(Vehicle.id == form.vehicle.data).first()
|
||||||
if not vehicle in current_user.vehicles:
|
if vehicle not in current_user.vehicles:
|
||||||
return render_template('selectVehice.html', form=form)
|
return render_template('selectVehice.html', form=form)
|
||||||
|
|
||||||
return redirect(url_for('create_pit_stop_form', vid=form.vehicle.data))
|
return redirect(url_for('create_pit_stop_form', vid=form.vehicle.data))
|
||||||
|
@ -143,7 +143,7 @@ def select_vehicle_for_new_pitstop():
|
||||||
@login_required
|
@login_required
|
||||||
def create_pit_stop_form(vid):
|
def create_pit_stop_form(vid):
|
||||||
vehicle = Vehicle.query.filter(Vehicle.id == vid).first()
|
vehicle = Vehicle.query.filter(Vehicle.id == vid).first()
|
||||||
if not vehicle in current_user.vehicles:
|
if vehicle not in current_user.vehicles:
|
||||||
return redirect(url_for('select_vehicle_for_new_pitstop'))
|
return redirect(url_for('select_vehicle_for_new_pitstop'))
|
||||||
|
|
||||||
if len(vehicle.pitstops) > 0:
|
if len(vehicle.pitstops) > 0:
|
||||||
|
@ -159,7 +159,7 @@ def create_pit_stop_form(vid):
|
||||||
db.session.add(new_stop)
|
db.session.add(new_stop)
|
||||||
vehicle.pitstops.append(new_stop)
|
vehicle.pitstops.append(new_stop)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(url_for('get_pit_stops'))
|
return redirect(url_for('get_pit_stops', _anchor= 'v' + str(vehicle.id)))
|
||||||
|
|
||||||
form.odometer.default = last_pitstop.odometer
|
form.odometer.default = last_pitstop.odometer
|
||||||
form.litres.default = last_pitstop.litres
|
form.litres.default = last_pitstop.litres
|
||||||
|
@ -171,9 +171,7 @@ def create_pit_stop_form(vid):
|
||||||
@app.route('/pitstops', methods=['GET'])
|
@app.route('/pitstops', methods=['GET'])
|
||||||
@login_required
|
@login_required
|
||||||
def get_pit_stops():
|
def get_pit_stops():
|
||||||
data = prepare_pit_stops(Pitstop.query.all())
|
return render_template('pitstops.html', user=current_user)
|
||||||
g.data['pitstops'] = data
|
|
||||||
return render_template('pitstops.html', data=g.data)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/manual', methods=['GET'])
|
@app.route('/manual', methods=['GET'])
|
||||||
|
@ -224,21 +222,3 @@ def get_statistics():
|
||||||
g.data['averageListresUsed'] = average_litres_used
|
g.data['averageListresUsed'] = average_litres_used
|
||||||
return render_template('statistics.html', data=g.data)
|
return render_template('statistics.html', data=g.data)
|
||||||
|
|
||||||
def prepare_pit_stops(pss):
|
|
||||||
pitstops = []
|
|
||||||
for pitstop_index in range(0, len(pss)):
|
|
||||||
p = dict()
|
|
||||||
p['odometer'] = pss[pitstop_index].odometer
|
|
||||||
p['litres'] = pss[pitstop_index].litres
|
|
||||||
p['date'] = pss[pitstop_index].date
|
|
||||||
pitstops.append(p)
|
|
||||||
for pitstop_index in range(1, len(pitstops)):
|
|
||||||
last = pitstops[pitstop_index - 1]
|
|
||||||
curr = pitstops[pitstop_index]
|
|
||||||
curr['distance'] = curr['odometer'] - last['odometer']
|
|
||||||
curr['average'] = 100 * curr['litres']/curr['distance']
|
|
||||||
last_date = last['date']
|
|
||||||
curr_date = curr['date']
|
|
||||||
curr['days'] = (curr_date - last_date).days
|
|
||||||
pitstops.reverse()
|
|
||||||
return pitstops
|
|
||||||
|
|
|
@ -1,39 +1,86 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
<div id="content">
|
||||||
|
<ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
|
||||||
|
{% for vehicle in current_user.vehicles %}
|
||||||
|
<li {% if loop.first %}class="active" {%endif %}>
|
||||||
|
<a href="#v{{vehicle.id}}" id="i{{vehicle.id}}" data-toggle="tab">
|
||||||
|
{{ vehicle.name }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
<div id="my-tab-content" class="tab-content">
|
||||||
|
{% for vehicle in current_user.vehicles %}
|
||||||
|
<div class="tab-pane {% if loop.first %}active{% endif %}" id="v{{vehicle.id}}">
|
||||||
|
<h3>{{vehicle.name}}</h3>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-striped table-bordered table-condensed">
|
<table class="table table-striped table-bordered table-condensed">
|
||||||
<tr>
|
<tr>
|
||||||
<th>
|
<th>
|
||||||
Date<br />
|
Date<br/>
|
||||||
Days
|
Days
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th>
|
||||||
Odometer<br />
|
Odometer<br/>
|
||||||
Distance
|
Distance
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th>
|
||||||
Litres<br />
|
Litres<br/>
|
||||||
Average
|
Average
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for pitstop in data['pitstops'] %}
|
{% for pitstop in vehicle.pitstops|reverse %}
|
||||||
|
{% if not loop.last %}
|
||||||
|
{% set days = (pitstop.date - vehicle.pitstops[vehicle.pitstops|length - loop.index - 1].date).days %}
|
||||||
|
{% set distance = pitstop.odometer - vehicle.pitstops[vehicle.pitstops|length - loop.index - 1].odometer %}
|
||||||
|
{% set average = (pitstop.litres / distance) * 100 %}
|
||||||
<tr class='pitstop'>
|
<tr class='pitstop'>
|
||||||
<td>
|
<td>
|
||||||
{{pitstop.date}}<br />
|
{{pitstop.date}}<br/>
|
||||||
{% if pitstop.days %}{{pitstop.days}}{% else %} --{% endif %} days
|
{{ days }} days
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{pitstop.odometer}} km<br />
|
{{pitstop.odometer}} km<br/>
|
||||||
{% if pitstop.distance %}{{pitstop.distance}}{% else %} --{% endif %} km
|
{{distance}} km
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{pitstop.litres}} l<br />
|
{{pitstop.litres}} l<br/>
|
||||||
{% if pitstop.average %}{{pitstop.average | round(2)}}{% else %} --{% endif %} l/100km
|
{{average | round(2)}} l/100km
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% else %}
|
||||||
|
<tr class='pitstop'>
|
||||||
|
<td>
|
||||||
|
{{pitstop.date}}<br/>
|
||||||
|
-- days
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{pitstop.odometer}} km<br/>
|
||||||
|
-- km
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{pitstop.litres}} l<br/>
|
||||||
|
-- l/100km
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
jQuery(document).ready(function ($) {
|
||||||
|
$('#tabs').tab();
|
||||||
|
if(window.location.hash != "") {
|
||||||
|
$('a[href="' + window.location.hash + '"]').click()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue