1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

Well, this works

This commit is contained in:
Steffo 2019-06-01 18:42:44 +02:00
parent 08993451e0
commit 860172916e
5 changed files with 35 additions and 17 deletions

12
royalnet/royalgamesweb.py Normal file
View file

@ -0,0 +1,12 @@
import os
from .web import create_app
from .web.blueprints import helloworld
class TestConfig:
DB_PATH = os.environ["DB_PATH"]
REQUIRED_TABLES = set()
app = create_app(TestConfig, [helloworld.bp])
app.run()

View file

@ -0,0 +1,3 @@
from .flaskserver import create_app
__all__ = ["create_app"]

View file

@ -4,12 +4,12 @@ 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()
f.g.alchemy_session = f.g.alchemy.Session()
return f.g.alchemy_session
@f.current_app.teardown_appcontext
def teardown_alchemy_session(*args, **kwargs):
def teardown_alchemy_session(*_, **__):
_alchemy_session = f.g.pop("alchemy_session", None)
if _alchemy_session is not None:
_alchemy_session.close()

View file

@ -0,0 +1,9 @@
import flask as f
bp = f.Blueprint("helloworld", __name__, url_prefix="/helloworld")
@bp.route("/")
def helloworld():
return "Hello world!"

View file

@ -1,19 +1,13 @@
import typing
import flask as f
import os
from ..database import Alchemy
def create_app(config_obj: typing.Type, blueprints: typing.List[f.Blueprint]):
app = f.Flask(__name__)
app.config["RN_ALCHEMY"] = Alchemy(os.environ["DB_PATH"], set())
app.config.from_object(config_obj)
with app.app_context():
from .alchemyhandler import alchemy_session as db_session
@app.route("/")
def test():
...
return repr(db_session)
if __name__ == "__main__":
app.run()
f.g.alchemy = Alchemy(app.config["DB_PATH"], app.config["REQUIRED_TABLES"])
for blueprint in blueprints:
app.register_blueprint(blueprint)
return app