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()
|
||||
|
||||
# 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'))
|
||||
|
||||
form = DeleteVehicleForm()
|
||||
|
@ -131,7 +131,7 @@ def select_vehicle_for_new_pitstop():
|
|||
|
||||
if form.validate_on_submit():
|
||||
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 redirect(url_for('create_pit_stop_form', vid=form.vehicle.data))
|
||||
|
@ -143,7 +143,7 @@ def select_vehicle_for_new_pitstop():
|
|||
@login_required
|
||||
def create_pit_stop_form(vid):
|
||||
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'))
|
||||
|
||||
if len(vehicle.pitstops) > 0:
|
||||
|
@ -159,7 +159,7 @@ def create_pit_stop_form(vid):
|
|||
db.session.add(new_stop)
|
||||
vehicle.pitstops.append(new_stop)
|
||||
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.litres.default = last_pitstop.litres
|
||||
|
@ -171,9 +171,7 @@ def create_pit_stop_form(vid):
|
|||
@app.route('/pitstops', methods=['GET'])
|
||||
@login_required
|
||||
def get_pit_stops():
|
||||
data = prepare_pit_stops(Pitstop.query.all())
|
||||
g.data['pitstops'] = data
|
||||
return render_template('pitstops.html', data=g.data)
|
||||
return render_template('pitstops.html', user=current_user)
|
||||
|
||||
|
||||
@app.route('/manual', methods=['GET'])
|
||||
|
@ -224,21 +222,3 @@ def get_statistics():
|
|||
g.data['averageListresUsed'] = average_litres_used
|
||||
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,7 +1,19 @@
|
|||
{% extends "layout.html" %}
|
||||
|
||||
{% 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">
|
||||
<table class="table table-striped table-bordered table-condensed">
|
||||
<tr>
|
||||
|
@ -18,22 +30,57 @@
|
|||
Average
|
||||
</th>
|
||||
</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'>
|
||||
<td>
|
||||
{{pitstop.date}}<br/>
|
||||
{% if pitstop.days %}{{pitstop.days}}{% else %} --{% endif %} days
|
||||
{{ days }} days
|
||||
</td>
|
||||
<td>
|
||||
{{pitstop.odometer}} km<br/>
|
||||
{% if pitstop.distance %}{{pitstop.distance}}{% else %} --{% endif %} km
|
||||
{{distance}} km
|
||||
</td>
|
||||
<td>
|
||||
{{pitstop.litres}} l<br/>
|
||||
{% if pitstop.average %}{{pitstop.average | round(2)}}{% else %} --{% endif %} l/100km
|
||||
{{average | round(2)}} l/100km
|
||||
</td>
|
||||
</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 %}
|
||||
</table>
|
||||
</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 %}
|
||||
|
|
Loading…
Reference in New Issue