1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00
AdvLabDB/advlabdb/__init__.py

53 lines
1.1 KiB
Python
Raw Normal View History

2022-05-29 16:13:28 +00:00
from flask_migrate import Migrate
2022-08-15 20:22:36 +00:00
from flask_security.datastore import SQLAlchemyUserDatastore
2022-11-10 12:20:32 +00:00
from flask_security.core import Security
2022-08-09 12:46:48 +00:00
2022-08-18 01:20:52 +00:00
from .config import get_settings, get_data_dir
2022-08-09 12:46:48 +00:00
from .models import db, User, Role
migrate = Migrate()
2022-08-18 01:20:52 +00:00
data_dir = get_data_dir()
settings = get_settings(data_dir)
2022-08-09 12:46:48 +00:00
user_datastore = SQLAlchemyUserDatastore(db, User, Role)
2022-11-10 12:20:32 +00:00
security = Security(datastore=user_datastore)
2022-08-09 12:46:48 +00:00
2022-08-18 01:20:52 +00:00
def create_app(create_for_server: bool = True):
2022-08-09 12:46:48 +00:00
from flask import Flask
app = Flask(__name__)
# Config
from .config import set_config
2022-08-18 01:20:52 +00:00
set_config(app, data_dir)
2022-08-09 12:46:48 +00:00
# Setup Flask-SQLAlchemy
db.init_app(app)
2022-08-08 20:51:52 +00:00
2022-08-09 12:46:48 +00:00
# Setup Flask-Migrate
migrate.init_app(app, db)
2022-04-18 16:04:48 +00:00
2022-08-09 12:46:48 +00:00
# Setup Flask-Security-Too
2022-11-10 12:20:32 +00:00
security.init_app(app)
2022-08-09 12:46:48 +00:00
if create_for_server:
# Setup views
from .adminModelViews import init_admin_model_views
2021-04-03 00:11:26 +00:00
2022-08-09 12:46:48 +00:00
init_admin_model_views(app)
2022-05-29 16:13:28 +00:00
2022-08-09 12:46:48 +00:00
from .assistantModelViews import init_assistant_model_views
2022-05-29 17:34:20 +00:00
2022-08-09 12:46:48 +00:00
init_assistant_model_views(app)
2022-08-09 12:46:48 +00:00
# Register blueprints
from .routes import bp as routes_bp
2021-04-03 00:11:26 +00:00
2022-08-09 12:46:48 +00:00
app.register_blueprint(routes_bp)
2022-05-29 17:34:20 +00:00
2022-08-09 12:46:48 +00:00
return app