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

51 lines
1.3 KiB
Python
Raw Normal View History

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
2022-05-29 16:13:28 +00:00
from flask_migrate import Migrate
2022-08-08 16:01:33 +00:00
from .config import set_config
2022-04-18 16:04:48 +00:00
app = Flask(__name__)
2021-04-03 00:11:26 +00:00
2022-08-08 16:01:33 +00:00
set_config(app)
2021-04-03 00:11:26 +00:00
2022-08-08 16:01:33 +00:00
# Setup Flask-SQLAlchemy
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)
2022-05-29 17:34:20 +00:00
# Setup Flask-Migrate
2022-05-29 16:13:28 +00:00
migrate = Migrate(app, db)
2022-05-29 17:34:20 +00:00
# Setup Flask-Admin
2022-08-08 16:01:33 +00:00
from .custom_classes import SecureAdminIndexView, SecureAssistantIndexView
2022-05-29 17:34:20 +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",
2021-06-02 21:43:41 +00:00
template_mode="bootstrap3",
2022-08-08 16:01:33 +00:00
index_view=SecureAdminIndexView(name="Home", url="/admin", endpoint="admin"),
2021-07-30 00:03:44 +00:00
)
assistantSpace = Admin(
app,
name="Assistant@AdvLabDB",
url="/assistant",
template_mode="bootstrap3",
2022-08-08 16:01:33 +00:00
index_view=SecureAssistantIndexView(name="Home", url="/assistant", endpoint="assistant"),
2021-06-02 21:43:41 +00:00
)
2022-05-08 19:26:25 +00:00
from . import models
2021-04-03 00:11:26 +00:00
2022-05-29 17:34:20 +00:00
user_datastore = SQLAlchemyUserDatastore(db, models.User, models.Role)
Security(app, user_datastore)
try:
2022-05-08 19:26:25 +00:00
from . 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"
)
2021-07-29 18:03:41 +00:00
print(str(ex))