mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
71 lines
1.8 KiB
Python
71 lines
1.8 KiB
Python
from os import environ
|
|
|
|
from flask import Flask
|
|
from flask_admin import Admin
|
|
from flask_security import Security, SQLAlchemyUserDatastore
|
|
from flask_security.models import fsqla_v2 as fsqla
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
from advlabdb.independent_funs import parse_bool
|
|
|
|
|
|
def set_from_env(app, var):
|
|
app.config[var] = environ[var]
|
|
|
|
|
|
load_dotenv(".env")
|
|
|
|
app = Flask(__name__)
|
|
|
|
app.config["SECURITY_EMAIL_VALIDATOR_ARGS"] = {
|
|
"check_deliverability": parse_bool(environ["CHECK_EMAIL_DELIVERABILITY"])
|
|
}
|
|
|
|
set_from_env(app, "SERVER_NAME")
|
|
|
|
set_from_env(app, "SECRET_KEY")
|
|
set_from_env(app, "SECURITY_PASSWORD_SALT")
|
|
|
|
set_from_env(app, "SQLALCHEMY_DATABASE_URI")
|
|
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
|
|
|
app.config["FLASK_ADMIN_FLUID_LAYOUT"] = True
|
|
|
|
db = SQLAlchemy(app)
|
|
|
|
fsqla.FsModels.set_db_info(db)
|
|
|
|
from advlabdb import customClasses
|
|
|
|
adminSpace = Admin(
|
|
app,
|
|
name="Admin@AdvLabDB",
|
|
url="/admin",
|
|
endpoint="adminSpace",
|
|
template_mode="bootstrap3",
|
|
index_view=customClasses.SecureAdminIndexView(name="Admin", url="/admin", endpoint="adminSpace"),
|
|
)
|
|
assistantSpace = Admin(
|
|
app,
|
|
name="Assistant@AdvLabDB",
|
|
url="/assistant",
|
|
endpoint="assistantSpace",
|
|
template_mode="bootstrap3",
|
|
index_view=customClasses.SecureAssistantIndexView(name="Assistant", url="/assistant", endpoint="assistantSpace"),
|
|
)
|
|
|
|
from advlabdb import models
|
|
|
|
# Setup Flask-Security
|
|
user_datastore = SQLAlchemyUserDatastore(db, models.User, models.Role)
|
|
Security(app, user_datastore)
|
|
|
|
try:
|
|
from advlabdb import routes, adminModelViews, assistantModelViews
|
|
except Exception as ex:
|
|
print(
|
|
"\nYou are probably initializing the database with a script. If not, then you have to worry about not being able to import in __init__.py!\n"
|
|
)
|
|
print(str(ex))
|