Added __builtins__ file and cleanup afterwards
This commit is contained in:
parent
e09a702896
commit
60ea5945be
|
@ -0,0 +1,36 @@
|
|||
# Python imports
|
||||
import os
|
||||
import builtins
|
||||
import threading
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from core.utils import Logger
|
||||
from core.utils import MessageHandler # Get simple message processor
|
||||
|
||||
|
||||
class BuiltinsException(Exception):
|
||||
...
|
||||
|
||||
|
||||
# NOTE: Threads WILL NOT die with parent's destruction.
|
||||
def threaded_wrapper(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=False).start()
|
||||
return wrapper
|
||||
|
||||
# NOTE: Threads WILL die with parent's destruction.
|
||||
def daemon_threaded_wrapper(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
|
||||
return wrapper
|
||||
|
||||
# NOTE: Just reminding myself we can add to builtins two different ways...
|
||||
# __builtins__.update({"event_system": Builtins()})
|
||||
builtins.app_name = ':::APP TITLE:::'
|
||||
builtins.threaded = threaded_wrapper
|
||||
builtins.daemon_threaded = daemon_threaded_wrapper
|
||||
builtins.ROOT_FILE_PTH = os.path.dirname(os.path.realpath(__file__))
|
||||
builtins.logger = Logger().get_logger()
|
||||
builtins.json_message = MessageHandler()
|
|
@ -1,32 +1,29 @@
|
|||
# Python imports
|
||||
import os
|
||||
|
||||
|
||||
# Lib imports
|
||||
from flask import Flask
|
||||
# OIDC Login path
|
||||
from flask_oidc import OpenIDConnect
|
||||
# Flask Login Path
|
||||
from flask_bcrypt import Bcrypt
|
||||
|
||||
from flask_login import current_user
|
||||
from flask_login import login_user
|
||||
from flask_login import logout_user
|
||||
from flask_login import LoginManager
|
||||
|
||||
# Apoplication imports
|
||||
from core.utils import Logger
|
||||
|
||||
|
||||
from .__builtins__ import *
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object("core.config.Config")
|
||||
# app.config.from_object("core.config.DevelopmentConfig")
|
||||
|
||||
|
||||
|
||||
oidc = OpenIDConnect(app)
|
||||
login_manager = LoginManager(app)
|
||||
bcrypt = Bcrypt(app)
|
||||
logger = Logger().get_logger()
|
||||
|
||||
|
||||
def oidc_loggedin():
|
||||
return oidc.user_loggedin
|
||||
|
@ -38,12 +35,12 @@ def oidc_isAdmin():
|
|||
return True
|
||||
return False
|
||||
|
||||
|
||||
app.jinja_env.globals['oidc_loggedin'] = oidc_loggedin
|
||||
app.jinja_env.globals['oidc_isAdmin'] = oidc_isAdmin
|
||||
app.jinja_env.globals['TITLE'] = app.config["TITLE"]
|
||||
|
||||
|
||||
|
||||
from core.models import db
|
||||
from core.models import User
|
||||
|
||||
|
|
|
@ -10,8 +10,6 @@ from datetime import timedelta
|
|||
|
||||
|
||||
|
||||
APP_NAME = ':::APP TITLE:::'
|
||||
ROOT_FILE_PTH = os.path.dirname(os.path.realpath(__file__))
|
||||
# This path is submitted as the redirect URI in certain code flows.
|
||||
# Change localhost%3A6969 to different port accordingly or change to your domain.
|
||||
REDIRECT_LINK = "http%3A%2F%2Flocalhost%3A6969%2F"
|
||||
|
@ -27,7 +25,7 @@ class FileGroups:
|
|||
|
||||
|
||||
class Config(object):
|
||||
TITLE = APP_NAME
|
||||
TITLE = app_name
|
||||
DEBUG = False
|
||||
TESTING = False
|
||||
SECRET_KEY = secrets.token_hex(32)
|
||||
|
|
|
@ -18,12 +18,8 @@ from core import db
|
|||
from core import User
|
||||
from core import LoginForm
|
||||
|
||||
from core.utils import MessageHandler # Get simple message processor
|
||||
|
||||
|
||||
|
||||
msgHandler = MessageHandler()
|
||||
|
||||
@app.route('/app-login', methods=['GET', 'POST'])
|
||||
def app_login():
|
||||
if current_user.is_authenticated or app.config["LOGIN_DISABLED"]:
|
||||
|
|
|
@ -16,13 +16,9 @@ from core import current_user
|
|||
from core import RegisterForm
|
||||
|
||||
from core.models import User
|
||||
from core.utils import MessageHandler # Get simple message processor
|
||||
|
||||
|
||||
|
||||
msgHandler = MessageHandler()
|
||||
|
||||
|
||||
@app.route('/app-register', methods=['GET', 'POST'])
|
||||
def app_register():
|
||||
if current_user.is_authenticated or app.config["REGISTER_DISABLED"]:
|
||||
|
|
|
@ -13,11 +13,6 @@ from ... import app
|
|||
from ... import oidc
|
||||
from ... import db
|
||||
|
||||
from ...utils import MessageHandler # Get simple message processor
|
||||
|
||||
|
||||
|
||||
msgHandler = MessageHandler()
|
||||
|
||||
|
||||
@app.route('/oidc-register', methods=['GET', 'POST'])
|
||||
|
|
|
@ -8,16 +8,9 @@ from flask_login import current_user
|
|||
# Application imports
|
||||
# Get from __init__
|
||||
from core import app
|
||||
from core import logger
|
||||
from core import oidc
|
||||
from core import db
|
||||
|
||||
from core.utils import MessageHandler # Get simple message processor
|
||||
|
||||
|
||||
|
||||
msgHandler = MessageHandler()
|
||||
|
||||
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
def home():
|
||||
|
|
Loading…
Reference in New Issue