mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Woah, this is progress
This commit is contained in:
parent
812ec627e8
commit
08993451e0
3 changed files with 34 additions and 10 deletions
|
@ -12,3 +12,5 @@ ffmpeg-python>=0.1.17
|
||||||
Sphinx>=2.0.1
|
Sphinx>=2.0.1
|
||||||
sphinx_rtd_theme>=0.4.3
|
sphinx_rtd_theme>=0.4.3
|
||||||
PyNaCl>=1.3.0
|
PyNaCl>=1.3.0
|
||||||
|
werkzeug>=0.15.4
|
||||||
|
flask>=1.0.3
|
||||||
|
|
18
royalnet/web/alchemyhandler.py
Normal file
18
royalnet/web/alchemyhandler.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import flask as f
|
||||||
|
import werkzeug.local
|
||||||
|
|
||||||
|
|
||||||
|
def get_alchemy_session():
|
||||||
|
if "alchemy_session" not in f.g:
|
||||||
|
f.g.alchemy_session = f.current_app.config["RN_ALCHEMY"].Session()
|
||||||
|
return f.g.alchemy_session
|
||||||
|
|
||||||
|
|
||||||
|
@f.current_app.teardown_appcontext
|
||||||
|
def teardown_alchemy_session(*args, **kwargs):
|
||||||
|
_alchemy_session = f.g.pop("alchemy_session", None)
|
||||||
|
if _alchemy_session is not None:
|
||||||
|
_alchemy_session.close()
|
||||||
|
|
||||||
|
|
||||||
|
alchemy_session = werkzeug.local.LocalProxy(get_alchemy_session)
|
|
@ -1,15 +1,19 @@
|
||||||
import typing
|
|
||||||
import flask as f
|
import flask as f
|
||||||
|
import os
|
||||||
from ..database import Alchemy
|
from ..database import Alchemy
|
||||||
|
|
||||||
|
|
||||||
class RoyalFlask:
|
app = f.Flask(__name__)
|
||||||
def __init__(self, config_obj: typing.Type):
|
app.config["RN_ALCHEMY"] = Alchemy(os.environ["DB_PATH"], set())
|
||||||
self.app = f.Flask(__name__)
|
with app.app_context():
|
||||||
self.app.config.from_object(config_obj)
|
from .alchemyhandler import alchemy_session as db_session
|
||||||
self.alchemy = Alchemy(self.app.config["RF_DATABASE_URI"], self.app.config["RF_REQUIRED_TABLES"])
|
|
||||||
for blueprint in self.app.config["RF_BLUEPRINTS"]:
|
|
||||||
self.app.register_blueprint(blueprint)
|
|
||||||
|
|
||||||
def debug(self):
|
|
||||||
self.app.run(host="127.0.0.1", port=1234, debug=True)
|
@app.route("/")
|
||||||
|
def test():
|
||||||
|
...
|
||||||
|
return repr(db_session)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run()
|
||||||
|
|
Loading…
Reference in a new issue