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

59 lines
1.8 KiB
Python

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
app = Flask(__name__)
app.debug = True # DEBUG
app.config["SECURITY_EMAIL_VALIDATOR_ARGS"] = {
"check_deliverability": False
} # Don't check email deliverability # DEBUG
app.config["SERVER_NAME"] = "127.0.0.1:5000" # DEBUG
# app.config["SERVER_NAME"] = "fprdb.physik.uni-mainz.de:5000" # DEBUG
app.config["SECRET_KEY"] = "dev"
app.config["SECURITY_PASSWORD_SALT"] = "devSalt" # os.environ.get("SECURITY_PASSWORD_SALT", "")
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///../db/advLab.db"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
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))