add page to plan a pitstop

This commit is contained in:
2017-11-12 15:38:32 +01:00
parent 28990f27fa
commit 9427ed50ad
5 changed files with 124 additions and 41 deletions

View File

@@ -3,3 +3,4 @@ from .admin import *
from .misc import *
from .pitstop import *
from .service import *
from .filling_stations import *

View File

@@ -6,9 +6,8 @@ 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, pitstop_service_key, \
get_event_line_for_vehicle
from ..tools import db_log_update, db_log_delete, db_log_add, pitstop_service_key, \
get_event_line_for_vehicle, update_filling_station_prices
from .. import app, db
@@ -50,6 +49,27 @@ def select_consumable_for_new_pitstop(vid):
return render_template('selectConsumableForVehicle.html', vehicle=vehicle, form=form)
@app.route('/pitstops/vehicle/<int:vid>/consumable/<int:cid>/plan', methods=['GET', 'POST'])
@login_required
def plan_pit_stop_form(vid, cid):
vehicle = Vehicle.query.get(vid)
if vehicle is None or vehicle not in current_user.vehicles:
return redirect(url_for('select_vehicle_for_new_pitstop'))
consumable = Consumable.query.get(cid)
if consumable not in vehicle.consumables:
return redirect(url_for('select_consumable_for_new_pitstop', vid=vid))
update_filling_station_prices([x.id for x in current_user.favourite_filling_stations])
offers = []
for fs in current_user.favourite_filling_stations:
if fs.open:
offers.append((fs, getattr(fs, consumable.ext_id),))
return render_template('planPitStopForm.html', vehicle=vehicle, consumable=consumable, offers=offers)
@app.route('/pitstops/vehicle/<int:vid>/consumable/<int:cid>/create', methods=['GET', 'POST'])
@login_required
def create_pit_stop_form(vid, cid):