flask_crud_app/app.py

49 lines
1.5 KiB
Python
Raw Permalink Normal View History

2025-02-12 10:29:36 +00:00
# Validate configuration before starting the app
from functions.validate_config import validate_config
2025-02-12 22:53:02 +00:00
from config import item_attributes, sql_conf
2025-02-12 10:29:36 +00:00
config_status = validate_config(item_attributes)
if config_status != "Ok":
raise SystemExit(f"Configuration Error: {config_status}")
# Import flask and sql to start the app
2025-01-30 09:58:34 +00:00
from flask import Flask, redirect
2025-01-29 05:27:19 +00:00
from sqlalchemy import exc
2025-02-11 18:45:53 +00:00
from definitions.models import *
2025-01-30 07:37:21 +00:00
# Import the Blueprints
from routes.viewall import viewall_bp
2025-02-11 07:47:57 +00:00
from routes.export_csv import export_csv_bp
2025-01-30 07:37:21 +00:00
from routes.viewasset import viewasset_bp
from routes.create import addasset_bp
from routes.update import update_bp
from routes.delete import delete_bp
from routes.upload import upload_bp
2025-02-01 18:19:02 +00:00
from routes.confirm_save import confirm_save_bp
2025-01-29 05:27:19 +00:00
app = Flask(__name__)
2025-01-30 07:37:21 +00:00
app.secret_key = 'your_secret_key' # Required for flashing messages and session
2025-02-12 22:53:02 +00:00
app.config['SQLALCHEMY_DATABASE_URI'] = f'mysql://{sql_conf.SQL_USER}:{sql_conf.SQL_PASSWORD}@{sql_conf.SQL_HOST}/{sql_conf.SQL_DB}'
2025-01-29 05:27:19 +00:00
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
2025-01-30 07:37:21 +00:00
# Register the Blueprints
app.register_blueprint(viewall_bp)
2025-02-11 07:47:57 +00:00
app.register_blueprint(export_csv_bp)
2025-01-30 07:37:21 +00:00
app.register_blueprint(viewasset_bp)
app.register_blueprint(addasset_bp)
app.register_blueprint(update_bp)
app.register_blueprint(delete_bp)
app.register_blueprint(upload_bp)
2025-02-01 18:19:02 +00:00
app.register_blueprint(confirm_save_bp)
2025-01-29 05:27:19 +00:00
2025-01-29 10:05:36 +00:00
with app.app_context():
2025-01-29 05:27:19 +00:00
db.create_all()
@app.route('/')
def index():
2025-01-29 10:38:32 +00:00
return redirect('/viewall')
2025-01-29 05:27:19 +00:00
if __name__ == '__main__':
app.run(host='localhost', port=5000)