react to closed stations
This commit is contained in:
@@ -49,27 +49,6 @@ 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):
|
||||
@@ -202,3 +181,64 @@ def get_pit_stops():
|
||||
user['vehicles'].append(v)
|
||||
|
||||
return render_template('pitstops.html', user=user)
|
||||
|
||||
|
||||
@app.route('/pitstops/plan/vehicle/select', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def select_vehicle_for_plan_pitstop():
|
||||
if len(current_user.vehicles) == 1:
|
||||
return redirect(url_for('select_consumable_for_plan_pitstop', vid=current_user.vehicles[0].id))
|
||||
|
||||
form = SelectVehicleForm()
|
||||
form.vehicle.choices = [(g.id, g.name) for g in current_user.vehicles]
|
||||
|
||||
if form.validate_on_submit():
|
||||
return redirect(url_for('select_consumable_for_plan_pitstop', vid=form.vehicle.data))
|
||||
|
||||
return render_template('selectVehicle.html', form=form)
|
||||
|
||||
|
||||
@app.route('/pitstops/plan/vehicle/<int:vid>/consumable/select', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def select_consumable_for_plan_pitstop(vid):
|
||||
vehicle = Vehicle.query.get(vid)
|
||||
if vehicle is None or vehicle not in current_user.vehicles:
|
||||
return redirect(url_for('select_consumable_for_plan_pitstop'))
|
||||
|
||||
if len(vehicle.consumables) == 0:
|
||||
flash('Please choose at least one consumable!', 'warning')
|
||||
return redirect(url_for('edit_vehicle', vid=vid))
|
||||
|
||||
if len(vehicle.consumables) == 1:
|
||||
return redirect(url_for('plan_pit_stop_form', vid=vid, cid=vehicle.consumables[0].id))
|
||||
|
||||
form = SelectConsumableForm()
|
||||
form.consumable.choices = [(g.id, g.name) for g in vehicle.consumables]
|
||||
|
||||
if form.validate_on_submit():
|
||||
return redirect(url_for('plan_pit_stop_form', vid=vid, cid=form.consumable.data))
|
||||
|
||||
return render_template('selectConsumableForVehicle.html', vehicle=vehicle, form=form)
|
||||
|
||||
|
||||
@app.route('/pitstops/plan/vehicle/<int:vid>/consumable/<int:cid>', 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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user