From 543d3e165813afd3a887e226c42d83d87c02defd Mon Sep 17 00:00:00 2001 From: Joachim Lusiardi Date: Sun, 12 Nov 2017 22:50:25 +0100 Subject: [PATCH] react to closed stations --- app/routes/pitstop.py | 82 ++++++++++++++++++++++-------- app/static/css/main.css | 3 ++ app/templates/layout.html | 1 + app/templates/planPitStopForm.html | 4 +- app/tools.py | 7 +-- 5 files changed, 71 insertions(+), 26 deletions(-) diff --git a/app/routes/pitstop.py b/app/routes/pitstop.py index 46a8dc1..77a145a 100644 --- a/app/routes/pitstop.py +++ b/app/routes/pitstop.py @@ -49,27 +49,6 @@ def select_consumable_for_new_pitstop(vid): return render_template('selectConsumableForVehicle.html', vehicle=vehicle, form=form) -@app.route('/pitstops/vehicle//consumable//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//consumable//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//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//consumable/', 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) + + diff --git a/app/static/css/main.css b/app/static/css/main.css index 3c06602..ac10814 100644 --- a/app/static/css/main.css +++ b/app/static/css/main.css @@ -121,3 +121,6 @@ th.headerSortDown { background-image: url(../img/up.gif); } +.filling_station_closed { + text-decoration: line-through; +} \ No newline at end of file diff --git a/app/templates/layout.html b/app/templates/layout.html index 173623c..9cc4579 100644 --- a/app/templates/layout.html +++ b/app/templates/layout.html @@ -1,5 +1,6 @@ {% macro navigation() -%} {% if current_user.email %} +
  • Plan Pitstop
  • Create Pitstop
  • Create Service
  • Statistics
  • diff --git a/app/templates/planPitStopForm.html b/app/templates/planPitStopForm.html index 0911681..44b8c0d 100644 --- a/app/templates/planPitStopForm.html +++ b/app/templates/planPitStopForm.html @@ -19,7 +19,7 @@ {% for offer in offers %} -
    +
    {{ offer[0].name }}
    {{ offer[0].street }} {{ offer[0].houseNumber }}
    @@ -30,7 +30,7 @@
    - + {{ offer[1] }} €/{{ consumable.unit }} diff --git a/app/tools.py b/app/tools.py index 09d233f..67e66a2 100644 --- a/app/tools.py +++ b/app/tools.py @@ -190,9 +190,10 @@ def update_filling_station_prices(ids): id = price station_status = prices[id] print(id, station_status) - map[id].diesel = station_status['diesel'] - map[id].e10 = station_status['e10'] - map[id].e5 = station_status['e5'] map[id].open = station_status['status'] == 'open' + if map[id].open: + map[id].diesel = station_status['diesel'] + map[id].e10 = station_status['e10'] + map[id].e5 = station_status['e5'] map[id].last_update = datetime.now() db.session.commit()