diff --git a/app/rollerverbrauch/__init__.py b/app/rollerverbrauch/__init__.py index cc496a8..47ba0e1 100644 --- a/app/rollerverbrauch/__init__.py +++ b/app/rollerverbrauch/__init__.py @@ -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 diff --git a/app/rollerverbrauch/templates/pitstops.html b/app/rollerverbrauch/templates/pitstops.html index a8e43c8..0088269 100644 --- a/app/rollerverbrauch/templates/pitstops.html +++ b/app/rollerverbrauch/templates/pitstops.html @@ -1,39 +1,86 @@ {% extends "layout.html" %} - {% block body %} +
+ +
+ {% for vehicle in current_user.vehicles %} +
+

{{vehicle.name}}

+
+ + + + + + + {% 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 %} + + + + + + {% else %} + + + + + + {% endif %} + {% endfor %} +
+ Date
+ Days +
+ Odometer
+ Distance +
+ Litres
+ Average +
+ {{pitstop.date}}
+ {{ days }} days +
+ {{pitstop.odometer}} km
+ {{distance}} km +
+ {{pitstop.litres}} l
+ {{average | round(2)}} l/100km +
+ {{pitstop.date}}
+ -- days +
+ {{pitstop.odometer}} km
+ -- km +
+ {{pitstop.litres}} l
+ -- l/100km +
+
+
+ {% endfor %} +
+
-
- - - - - - - {% for pitstop in data['pitstops'] %} - - - - - - {% endfor %} -
- Date
- Days -
- Odometer
- Distance -
- Litres
- Average -
- {{pitstop.date}}
- {% if pitstop.days %}{{pitstop.days}}{% else %} --{% endif %} days -
- {{pitstop.odometer}} km
- {% if pitstop.distance %}{{pitstop.distance}}{% else %} --{% endif %} km -
- {{pitstop.litres}} l
- {% if pitstop.average %}{{pitstop.average | round(2)}}{% else %} --{% endif %} l/100km -
-
+ + {% endblock %}