wip
This commit is contained in:
parent
3b2f1db4ce
commit
5c16964b76
47 changed files with 2080 additions and 1053 deletions
|
@ -2,43 +2,44 @@ from flask import Flask, g, redirect, url_for, render_template
|
|||
import datetime
|
||||
import os
|
||||
|
||||
def create_app(config_name='development'):
|
||||
app = Flask(__name__,
|
||||
static_folder='static',
|
||||
template_folder='templates')
|
||||
|
||||
|
||||
def create_app(config_name="development"):
|
||||
app = Flask(__name__, static_folder="static", template_folder="templates")
|
||||
|
||||
# Load configuration
|
||||
if config_name == 'production':
|
||||
app.config.from_object('config.ProductionConfig')
|
||||
elif config_name == 'testing':
|
||||
app.config.from_object('config.TestingConfig')
|
||||
if config_name == "production":
|
||||
app.config.from_object("config.ProductionConfig")
|
||||
elif config_name == "testing":
|
||||
app.config.from_object("config.TestingConfig")
|
||||
else:
|
||||
app.config.from_object('config.DevelopmentConfig')
|
||||
|
||||
app.config.from_object("config.DevelopmentConfig")
|
||||
|
||||
# Initialize extensions
|
||||
from app.core.extensions import db, migrate, login_manager, bcrypt, limiter, csrf
|
||||
|
||||
db.init_app(app)
|
||||
migrate.init_app(app, db)
|
||||
login_manager.init_app(app)
|
||||
bcrypt.init_app(app)
|
||||
csrf.init_app(app)
|
||||
limiter.init_app(app)
|
||||
|
||||
|
||||
# Initialize login manager
|
||||
from app.core.auth import User
|
||||
|
||||
|
||||
@login_manager.user_loader
|
||||
def load_user(user_id):
|
||||
return User.query.get(int(user_id))
|
||||
|
||||
login_manager.login_view = 'auth.login'
|
||||
login_manager.login_message = 'Please log in to access this page.'
|
||||
login_manager.login_message_category = 'info'
|
||||
|
||||
|
||||
login_manager.login_view = "auth.login"
|
||||
login_manager.login_message = "Please log in to access this page."
|
||||
login_manager.login_message_category = "info"
|
||||
|
||||
# Register template filters
|
||||
from app.core.template_filters import bp as filters_bp
|
||||
|
||||
app.register_blueprint(filters_bp)
|
||||
|
||||
|
||||
# Create database tables without seeding any data
|
||||
with app.app_context():
|
||||
try:
|
||||
|
@ -46,31 +47,44 @@ def create_app(config_name='development'):
|
|||
print("Database tables created successfully")
|
||||
except Exception as e:
|
||||
print(f"Error with database setup: {e}")
|
||||
|
||||
|
||||
# Register blueprints
|
||||
from app.routes.auth import bp as auth_bp
|
||||
|
||||
app.register_blueprint(auth_bp)
|
||||
|
||||
|
||||
from app.routes.dashboard import bp as dashboard_bp
|
||||
|
||||
app.register_blueprint(dashboard_bp)
|
||||
|
||||
|
||||
from app.routes.ipam import bp as ipam_bp
|
||||
|
||||
app.register_blueprint(ipam_bp)
|
||||
|
||||
|
||||
from app.routes.api import bp as api_bp
|
||||
|
||||
app.register_blueprint(api_bp)
|
||||
|
||||
|
||||
from app.routes.importexport import bp as importexport_bp
|
||||
|
||||
app.register_blueprint(importexport_bp)
|
||||
|
||||
# Add static assets blueprint
|
||||
from app.routes.static import bp as static_bp
|
||||
|
||||
app.register_blueprint(static_bp)
|
||||
|
||||
# Add error handlers
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(e):
|
||||
return render_template('errors/404.html', title='Page Not Found'), 404
|
||||
return render_template("errors/404.html", title="Page Not Found"), 404
|
||||
|
||||
@app.errorhandler(500)
|
||||
def internal_server_error(e):
|
||||
return render_template('errors/500.html', title='Server Error'), 500
|
||||
return render_template("errors/500.html", title="Server Error"), 500
|
||||
|
||||
@app.errorhandler(403)
|
||||
def forbidden(e):
|
||||
return render_template('errors/403.html', title='Forbidden'), 403
|
||||
|
||||
return app
|
||||
return render_template("errors/403.html", title="Forbidden"), 403
|
||||
|
||||
return app
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue