From bceb9181ee09505805ca1681c8f4c3b23eb55b39 Mon Sep 17 00:00:00 2001 From: Joachim Lusiardi Date: Tue, 1 Nov 2016 19:48:24 +0100 Subject: [PATCH] sorting for events --- app/routes/pitstop.py | 9 +++------ app/tools.py | 5 +++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/routes/pitstop.py b/app/routes/pitstop.py index e69a223..ea8d630 100644 --- a/app/routes/pitstop.py +++ b/app/routes/pitstop.py @@ -7,7 +7,7 @@ from datetime import date from ..entities import Vehicle, Consumable, Pitstop from ..forms import SelectVehicleForm, SelectConsumableForm, CreatePitstopForm, EditPitstopForm, DeletePitStopForm from ..tools import db_log_update, db_log_delete, db_log_add, get_latest_pitstop_for_vehicle, \ - get_latest_pitstop_for_vehicle_and_consumable, compute_lower_limits_for_new_pitstop + get_latest_pitstop_for_vehicle_and_consumable, compute_lower_limits_for_new_pitstop, pitstop_service_key from .. import app, db @@ -161,10 +161,6 @@ def edit_pit_stop_form(pid): return render_template('editPitStopForm.html', form=form, vehicle=vehicle, messages=messages) -def pitstop_service_key(x): - return x.odometer - - @app.route('/pitstops', methods=['GET']) @login_required def get_pit_stops(): @@ -177,10 +173,11 @@ def get_pit_stops(): data.append(pitstop) for service in vehicle.services: data.append(service) + data.sort(key=pitstop_service_key) v = { 'id': vehicle.id, 'name': vehicle.name, - 'data': sorted(data, key=pitstop_service_key) + 'data': data } user['vehicles'].append(v) diff --git a/app/tools.py b/app/tools.py index cd8108a..f1e1b53 100644 --- a/app/tools.py +++ b/app/tools.py @@ -175,3 +175,8 @@ def compute_lower_limits_for_new_pitstop(latest_pitstop, last_pitstop_consumable # # No existing pitstop at all: insert fake data # return Pitstop(0, 0, date(1970, 1, 1), 0, None) + +def pitstop_service_key(x): + return x.odometer, x.date + +