remove the plan pitstop feature
Co-authored-by: Joachim Lusiardi <joachim@lusiardi.de> Co-committed-by: Joachim Lusiardi <joachim@lusiardi.de>
This commit was merged in pull request #11.
This commit is contained in:
@@ -3,5 +3,4 @@ from .admin import *
|
||||
from .misc import *
|
||||
from .pitstop import *
|
||||
from .service import *
|
||||
from .filling_stations import *
|
||||
from .regular_cost import *
|
||||
|
||||
@@ -13,13 +13,9 @@ from .. import app, db, user_datastore
|
||||
@app.route("/account", methods=["GET"])
|
||||
@login_required
|
||||
def get_account_page():
|
||||
stations = [x.as_dict() for x in current_user.favourite_filling_stations]
|
||||
for station in stations:
|
||||
station["state"] = "favourite"
|
||||
return render_template(
|
||||
"account.html",
|
||||
map_pos=(current_user.home_lat, current_user.home_long, current_user.home_zoom),
|
||||
fs=json.dumps(stations),
|
||||
)
|
||||
|
||||
|
||||
@@ -142,24 +138,3 @@ def delete_account():
|
||||
|
||||
return render_template("deleteAccountForm.html", form=form)
|
||||
|
||||
|
||||
@app.route("/account/home", methods=["GET"])
|
||||
@login_required
|
||||
def get_users_home():
|
||||
return jsonify(
|
||||
{
|
||||
"lat": float(current_user.home_lat),
|
||||
"long": float(current_user.home_long),
|
||||
"zoom": current_user.home_zoom,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@app.route("/account/home", methods=["POST"])
|
||||
@login_required
|
||||
def set_users_home():
|
||||
current_user.home_lat = request.json["lat"]
|
||||
current_user.home_long = request.json["long"]
|
||||
current_user.home_zoom = request.json["zoom"]
|
||||
db.session.commit()
|
||||
return jsonify({})
|
||||
|
||||
@@ -22,8 +22,6 @@ def get_admin_page():
|
||||
@login_required
|
||||
def create_consumable():
|
||||
form = CreateConsumableForm()
|
||||
choices = [(0, ''), (1, 'diesel'), (2, 'e5'), (3, 'e10')]
|
||||
form.ext_id.choices = choices
|
||||
|
||||
# preinitialize the defaults with potentially existing values from a try before
|
||||
if form.name.data is not None:
|
||||
@@ -32,7 +30,7 @@ def create_consumable():
|
||||
form.unit.default = form.unit.data
|
||||
|
||||
if form.validate_on_submit():
|
||||
new_consumable = Consumable(form.name.data, choices[form.ext_id.data][1], form.unit.data)
|
||||
new_consumable = Consumable(form.name.data, form.unit.data)
|
||||
db.session.add(new_consumable)
|
||||
try:
|
||||
db.session.commit()
|
||||
@@ -72,28 +70,19 @@ def edit_consumable(cid):
|
||||
return redirect(url_for('get_admin_page'))
|
||||
|
||||
form = EditConsumableForm()
|
||||
choices = [(0, ''), (1, 'diesel'), (2, 'e5'), (3, 'e10')]
|
||||
form.ext_id.choices = choices
|
||||
|
||||
form.name.default = consumable.name
|
||||
form.unit.default = consumable.unit
|
||||
form.ext_id.default = 3
|
||||
for c in choices:
|
||||
if c[1] == consumable.ext_id:
|
||||
form.ext_id.default = c[0]
|
||||
|
||||
# preinitialize the defaults with potentially existing values from a try before
|
||||
if form.name.data is not None:
|
||||
form.name.default = form.name.data
|
||||
if form.unit.data is not None:
|
||||
form.unit.default = form.unit.data
|
||||
if form.ext_id.data is not None:
|
||||
form.ext_id.default = form.ext_id.data
|
||||
|
||||
if form.validate_on_submit():
|
||||
consumable.name = form.name.data
|
||||
consumable.unit = form.unit.data
|
||||
consumable.ext_id = choices[form.ext_id.data][1]
|
||||
try:
|
||||
db.session.commit()
|
||||
db_log_update(consumable)
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
from flask import request, jsonify
|
||||
from flask_security import login_required
|
||||
from flask_security.core import current_user
|
||||
import requests
|
||||
|
||||
from ..entities import FillingStation
|
||||
from .. import app, db
|
||||
|
||||
|
||||
@app.route('/filling_stations/favourites/toggle/<fsid>')
|
||||
def add_favourite_filling_stations(fsid):
|
||||
favourite_ids = {x.id: x for x in current_user.favourite_filling_stations}
|
||||
|
||||
if fsid in favourite_ids:
|
||||
current_user.favourite_filling_stations.remove(favourite_ids[fsid])
|
||||
state = 'normal'
|
||||
else:
|
||||
fs = FillingStation.query.filter(FillingStation.id == fsid).first()
|
||||
current_user.favourite_filling_stations.append(fs)
|
||||
state = 'favourite'
|
||||
db.session.commit()
|
||||
return jsonify({'state': state})
|
||||
|
||||
|
||||
@app.route('/filling_stations', methods=['GET'])
|
||||
@login_required
|
||||
def query_filling_stations():
|
||||
api_key = app.config['TANKERKOENIG_API_KEY']
|
||||
|
||||
latitude = request.args.get('latitude')
|
||||
longitude = request.args.get('longitude')
|
||||
radius = request.args.get('radius', default=1.5)
|
||||
gas_type = request.args.get('type', default='all')
|
||||
sort = request.args.get('sort', default='dist')
|
||||
|
||||
url = 'https://creativecommons.tankerkoenig.de/json/list.php'
|
||||
params = {
|
||||
'lat': latitude, 'lng': longitude, 'rad': radius, 'apikey': api_key, 'type': gas_type, 'sort': sort
|
||||
}
|
||||
response = requests.get(url, params=params)
|
||||
data = response.json()
|
||||
for station in data['stations']:
|
||||
fs = FillingStation.query.filter(FillingStation.id == station['id']).first()
|
||||
if not fs:
|
||||
fs = FillingStation()
|
||||
fs.id = station['id']
|
||||
fs.brand = station['brand']
|
||||
fs.lat = station['lat']
|
||||
fs.lng = station['lng']
|
||||
fs.name = station['name']
|
||||
fs.street = station['street']
|
||||
fs.place = station['place']
|
||||
fs.houseNumber = station['houseNumber']
|
||||
fs.postCode = station['postCode']
|
||||
db.session.add(fs)
|
||||
if fs in current_user.favourite_filling_stations:
|
||||
station['state'] = 'favourite'
|
||||
else:
|
||||
station['state'] = 'normal'
|
||||
db.session.commit()
|
||||
return jsonify(data)
|
||||
@@ -20,7 +20,6 @@ from ..tools import (
|
||||
db_log_add,
|
||||
pitstop_service_key,
|
||||
get_event_line_for_vehicle,
|
||||
update_filling_station_prices,
|
||||
RegularCostInstance,
|
||||
calculate_regular_cost_instances,
|
||||
get_users_active_vehicle,
|
||||
@@ -229,86 +228,3 @@ 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:
|
||||
offers.append(
|
||||
(
|
||||
fs,
|
||||
getattr(fs, consumable.ext_id),
|
||||
)
|
||||
)
|
||||
|
||||
return render_template(
|
||||
"planPitStopForm.html", vehicle=vehicle, consumable=consumable, offers=offers
|
||||
)
|
||||
|
||||
@@ -18,7 +18,6 @@ from ..tools import (
|
||||
db_log_add,
|
||||
pitstop_service_key,
|
||||
get_event_line_for_vehicle,
|
||||
update_filling_station_prices,
|
||||
get_users_active_vehicle,
|
||||
)
|
||||
from .. import app, db
|
||||
|
||||
Reference in New Issue
Block a user