38 lines
911 B
Python
38 lines
911 B
Python
from flask import Flask
|
|
from test.vehicle_data import vehicle_data
|
|
|
|
from .extensions import db, ma
|
|
from .models.vehicle import Vehicle
|
|
|
|
def create_app():
|
|
app = Flask(__name__)
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite3'
|
|
|
|
db.init_app(app)
|
|
ma.init_app(app)
|
|
|
|
@app.cli.command("reset-db")
|
|
def reset_db():
|
|
db.drop_all()
|
|
db.create_all()
|
|
|
|
|
|
@app.cli.command("create-vehicles")
|
|
def create_vehicles():
|
|
for vehicle in vehicle_data:
|
|
db.session.add(Vehicle(**vehicle))
|
|
db.session.commit()
|
|
|
|
from .routes.vehicle import vehicle_routes
|
|
app.register_blueprint(vehicle_routes)
|
|
|
|
from .routes.shift import shift_routes
|
|
app.register_blueprint(shift_routes)
|
|
|
|
from .routes.auto import auto_routes
|
|
app.register_blueprint(auto_routes)
|
|
|
|
return app
|
|
|