49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
from flask import Flask
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
from flask_login import LoginManager
|
|
from flask_migrate import Migrate
|
|
from flask_mail import Mail
|
|
from config import config
|
|
import os
|
|
|
|
# Initialize extensions
|
|
db = SQLAlchemy()
|
|
login_manager = LoginManager()
|
|
migrate = Migrate()
|
|
mail = Mail()
|
|
|
|
def create_app(config_name='default'):
|
|
app = Flask(__name__)
|
|
|
|
# Load configuration
|
|
app.config.from_object(config[config_name])
|
|
|
|
# Initialize extensions with app
|
|
db.init_app(app)
|
|
login_manager.init_app(app)
|
|
migrate.init_app(app, db)
|
|
mail.init_app(app)
|
|
|
|
# Configure login manager
|
|
login_manager.login_view = 'auth.login'
|
|
login_manager.login_message = 'Please log in to access this page.'
|
|
login_manager.login_message_category = 'info'
|
|
|
|
# Create upload directory if it doesn't exist
|
|
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
|
|
|
# Register blueprints (import here to avoid circular imports)
|
|
from app.routes import auth, dashboard, inspections, templates, reports, facilities
|
|
|
|
app.register_blueprint(auth.bp)
|
|
app.register_blueprint(dashboard.bp)
|
|
app.register_blueprint(inspections.bp)
|
|
app.register_blueprint(templates.bp)
|
|
app.register_blueprint(reports.bp)
|
|
app.register_blueprint(facilities.bp)
|
|
|
|
# Create database tables
|
|
with app.app_context():
|
|
db.create_all()
|
|
|
|
return app |