sorting for events

This commit is contained in:
Joachim Lusiardi 2016-11-01 19:48:24 +01:00
parent 086c643365
commit bceb9181ee
2 changed files with 8 additions and 6 deletions

View File

@ -7,7 +7,7 @@ from datetime import date
from ..entities import Vehicle, Consumable, Pitstop from ..entities import Vehicle, Consumable, Pitstop
from ..forms import SelectVehicleForm, SelectConsumableForm, CreatePitstopForm, EditPitstopForm, DeletePitStopForm 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, \ 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 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) return render_template('editPitStopForm.html', form=form, vehicle=vehicle, messages=messages)
def pitstop_service_key(x):
return x.odometer
@app.route('/pitstops', methods=['GET']) @app.route('/pitstops', methods=['GET'])
@login_required @login_required
def get_pit_stops(): def get_pit_stops():
@ -177,10 +173,11 @@ def get_pit_stops():
data.append(pitstop) data.append(pitstop)
for service in vehicle.services: for service in vehicle.services:
data.append(service) data.append(service)
data.sort(key=pitstop_service_key)
v = { v = {
'id': vehicle.id, 'id': vehicle.id,
'name': vehicle.name, 'name': vehicle.name,
'data': sorted(data, key=pitstop_service_key) 'data': data
} }
user['vehicles'].append(v) user['vehicles'].append(v)

View File

@ -175,3 +175,8 @@ def compute_lower_limits_for_new_pitstop(latest_pitstop, last_pitstop_consumable
# # No existing pitstop at all: insert fake data # # No existing pitstop at all: insert fake data
# return Pitstop(0, 0, date(1970, 1, 1), 0, None) # return Pitstop(0, 0, date(1970, 1, 1), 0, None)
def pitstop_service_key(x):
return x.odometer, x.date