2021-03-18 13:53:55 +00:00
|
|
|
from flask import Flask
|
2021-06-02 21:43:41 +00:00
|
|
|
from flask_admin import Admin
|
2021-04-03 00:11:26 +00:00
|
|
|
from flask_security import Security, SQLAlchemyUserDatastore
|
|
|
|
from flask_security.models import fsqla_v2 as fsqla
|
2021-06-02 21:43:41 +00:00
|
|
|
from flask_sqlalchemy import SQLAlchemy
|
2021-03-18 13:53:55 +00:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
2021-06-28 16:43:13 +00:00
|
|
|
|
2021-06-02 21:43:41 +00:00
|
|
|
app.debug = True # DEBUG
|
2021-04-03 00:11:26 +00:00
|
|
|
|
2021-06-28 16:43:13 +00:00
|
|
|
app.config["SECURITY_EMAIL_VALIDATOR_ARGS"] = {
|
|
|
|
"check_deliverability": False
|
|
|
|
} # Don't check email deliverability # DEBUG
|
|
|
|
|
2021-06-02 21:43:41 +00:00
|
|
|
app.config["SERVER_NAME"] = "127.0.0.1:5000" # DEBUG
|
2021-09-11 20:52:38 +00:00
|
|
|
# app.config["SERVER_NAME"] = "fprdb.physik.uni-mainz.de:5000" # DEBUG
|
2021-04-24 10:05:58 +00:00
|
|
|
|
2021-03-18 13:53:55 +00:00
|
|
|
app.config["SECRET_KEY"] = "dev"
|
2021-06-02 21:43:41 +00:00
|
|
|
app.config["SECURITY_PASSWORD_SALT"] = "devSalt" # os.environ.get("SECURITY_PASSWORD_SALT", "")
|
2021-04-03 00:11:26 +00:00
|
|
|
|
2022-01-13 01:25:31 +00:00
|
|
|
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///../db/advLab.db"
|
2021-07-13 23:58:35 +00:00
|
|
|
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
|
|
|
|
2021-03-18 13:53:55 +00:00
|
|
|
db = SQLAlchemy(app)
|
|
|
|
|
2021-04-03 00:11:26 +00:00
|
|
|
fsqla.FsModels.set_db_info(db)
|
|
|
|
|
2021-04-18 23:33:46 +00:00
|
|
|
from advlabdb import customClasses
|
2021-06-02 21:43:41 +00:00
|
|
|
|
2021-07-30 00:03:44 +00:00
|
|
|
adminSpace = Admin(
|
2021-06-02 21:43:41 +00:00
|
|
|
app,
|
|
|
|
name="Admin@AdvLabDB",
|
2021-07-30 00:03:44 +00:00
|
|
|
url="/admin",
|
|
|
|
endpoint="adminSpace",
|
2021-06-02 21:43:41 +00:00
|
|
|
template_mode="bootstrap3",
|
2022-02-23 23:08:14 +00:00
|
|
|
index_view=customClasses.SecureAdminIndexView(name="Admin", url="/admin", endpoint="adminSpace"),
|
2021-07-30 00:03:44 +00:00
|
|
|
)
|
|
|
|
assistantSpace = Admin(
|
|
|
|
app,
|
|
|
|
name="Assistant@AdvLabDB",
|
|
|
|
url="/assistant",
|
|
|
|
endpoint="assistantSpace",
|
|
|
|
template_mode="bootstrap3",
|
2022-02-24 00:10:04 +00:00
|
|
|
index_view=customClasses.SecureAssistantIndexView(name="Assistant", url="/assistant", endpoint="assistantSpace"),
|
2021-06-02 21:43:41 +00:00
|
|
|
)
|
2021-04-18 23:33:46 +00:00
|
|
|
|
2021-03-18 13:53:55 +00:00
|
|
|
from advlabdb import models
|
2021-04-03 00:11:26 +00:00
|
|
|
|
|
|
|
# Setup Flask-Security
|
|
|
|
user_datastore = SQLAlchemyUserDatastore(db, models.User, models.Role)
|
2021-04-18 23:33:46 +00:00
|
|
|
Security(app, user_datastore)
|
2021-04-03 00:11:26 +00:00
|
|
|
|
2021-07-14 02:26:18 +00:00
|
|
|
try:
|
2021-07-30 00:50:49 +00:00
|
|
|
from advlabdb import routes, adminModelViews, assistantModelViews
|
2021-07-14 02:26:18 +00:00
|
|
|
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"
|
|
|
|
)
|
2021-07-29 18:03:41 +00:00
|
|
|
print(str(ex))
|