batman
This commit is contained in:
commit
345a801c40
33 changed files with 5499 additions and 0 deletions
56
app/__init__.py
Normal file
56
app/__init__.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
# App package initialization
|
||||
from flask import Flask
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_login import LoginManager
|
||||
from flask_migrate import Migrate
|
||||
from flask_wtf.csrf import CSRFProtect
|
||||
import os
|
||||
from datetime import timedelta
|
||||
|
||||
# Initialize SQLAlchemy outside of create_app
|
||||
db = SQLAlchemy()
|
||||
login_manager = LoginManager()
|
||||
csrf = CSRFProtect()
|
||||
migrate = Migrate()
|
||||
|
||||
# App configuration
|
||||
class Config:
|
||||
SECRET_KEY = os.environ.get('SECRET_KEY') or os.urandom(24)
|
||||
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or 'sqlite:///docs.db'
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
PERMANENT_SESSION_LIFETIME = timedelta(hours=12)
|
||||
SESSION_TYPE = 'filesystem'
|
||||
|
||||
def create_app(config_class=Config):
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(config_class)
|
||||
|
||||
# Initialize extensions
|
||||
db.init_app(app)
|
||||
login_manager.init_app(app)
|
||||
csrf.init_app(app)
|
||||
migrate.init_app(app, db)
|
||||
|
||||
# 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'
|
||||
|
||||
# Configure session
|
||||
app.config['SESSION_PERMANENT'] = True
|
||||
|
||||
# Register blueprints
|
||||
from app.routes import main as main_bp
|
||||
app.register_blueprint(main_bp)
|
||||
|
||||
from app.auth import bp as auth_bp
|
||||
app.register_blueprint(auth_bp, url_prefix='/auth')
|
||||
|
||||
return app
|
||||
|
||||
# Create app instance
|
||||
app = create_app()
|
||||
|
||||
# Import models after db initialization to avoid circular imports
|
||||
from app.models.document import Document, Category, Tag
|
||||
from app.models.user import User
|
Loading…
Add table
Add a link
Reference in a new issue