59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
"""
|
|||
|
|
Flask job application system - Application factory module.
|
||
|
|
"""
|
||
|
|
from pathlib import Path
|
||
|
|
from flask import Flask, redirect, url_for, flash
|
||
|
|
from flask_mail import Mail
|
||
|
|
from flask_wtf.csrf import CSRFProtect, CSRFError
|
||
|
|
from config import Config
|
||
|
|
|
||
|
|
# Initialize extensions (not bound to app yet)
|
||
|
|
mail = Mail()
|
||
|
|
csrf = CSRFProtect()
|
||
|
|
|
||
|
|
|
||
|
|
def create_app(config_class=Config):
|
||
|
|
"""
|
||
|
|
Application factory function.
|
||
|
|
Creates and configures the Flask application instance.
|
||
|
|
|
||
|
|
Args:
|
||
|
|
config_class: Configuration class to use (defaults to Config)
|
||
|
|
|
||
|
|
Returns:
|
||
|
|
Configured Flask application instance
|
||
|
|
"""
|
||
|
|
# Create Flask app instance
|
||
|
|
# Specify template and static folders relative to project root (parent of app/)
|
||
|
|
app = Flask(__name__,
|
||
|
|
template_folder='../templates',
|
||
|
|
static_folder='../static')
|
||
|
|
|
||
|
|
# Load configuration
|
||
|
|
app.config.from_object(config_class)
|
||
|
|
|
||
|
|
# Initialize extensions with app
|
||
|
|
mail.init_app(app)
|
||
|
|
csrf.init_app(app)
|
||
|
|
|
||
|
|
# Ensure applications folder exists
|
||
|
|
Path(app.config['APPLICATIONS_FOLDER']).mkdir(exist_ok=True)
|
||
|
|
|
||
|
|
# Register error handlers
|
||
|
|
@app.errorhandler(CSRFError)
|
||
|
|
def handle_csrf_error(e):
|
||
|
|
"""Handle CSRF validation errors."""
|
||
|
|
flash('Sicherheitsfehler: Die Sitzung ist abgelaufen. Bitte laden Sie die Seite neu und versuchen Sie es erneut.', 'error')
|
||
|
|
return redirect(url_for('page1_email')), 400
|
||
|
|
|
||
|
|
@app.errorhandler(429)
|
||
|
|
def handle_rate_limit_error(e):
|
||
|
|
"""Handle rate limit errors."""
|
||
|
|
return str(e), 429
|
||
|
|
|
||
|
|
# Register routes
|
||
|
|
from app.routes import register_routes
|
||
|
|
register_routes(app, mail)
|
||
|
|
|
||
|
|
return app
|