diff --git a/royalnet/database/alchemy.py b/royalnet/database/alchemy.py index d2b86469..74a3a499 100644 --- a/royalnet/database/alchemy.py +++ b/royalnet/database/alchemy.py @@ -1,7 +1,7 @@ import typing from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.orm import sessionmaker +from sqlalchemy.orm import sessionmaker, scoped_session from contextlib import contextmanager, asynccontextmanager from ..utils import asyncify # noinspection PyUnresolvedReferences diff --git a/royalnet/web/alchemyhandler.py b/royalnet/web/alchemyhandler.py deleted file mode 100644 index 6cf2aa8e..00000000 --- a/royalnet/web/alchemyhandler.py +++ /dev/null @@ -1,21 +0,0 @@ -import flask as f -from werkzeug.local import LocalProxy - - -alchemy = f.current_app.config["ALCHEMY"] - - -def get_alchemy_session(): - if "alchemy_session" not in f.g: - f.g.alchemy_session = alchemy.Session() - return f.g.alchemy_session - - -@f.current_app.teardown_appcontext -def teardown_alchemy_session(*_, **__): - _alchemy_session = f.g.pop("alchemy_session", None) - if _alchemy_session is not None: - _alchemy_session.close() - - -alchemy_session = LocalProxy(get_alchemy_session) diff --git a/royalnet/web/blueprints/__init__.py b/royalnet/web/blueprints/__init__.py index 2097b48f..dba30e4e 100644 --- a/royalnet/web/blueprints/__init__.py +++ b/royalnet/web/blueprints/__init__.py @@ -1,7 +1,5 @@ -from .helloworld import bp as helloworld -from .testing import bp as testing from .home import bp as home from .wikiview import bp as wikiview from .tglogin import bp as tglogin -__all__ = ["helloworld", "testing", "home", "wikiview", "tglogin"] +__all__ = ["home", "wikiview", "tglogin"] diff --git a/royalnet/web/blueprints/helloworld/__init__.py b/royalnet/web/blueprints/helloworld/__init__.py deleted file mode 100644 index 21228d40..00000000 --- a/royalnet/web/blueprints/helloworld/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ -import flask as f -from ... import Royalprint - - -bp = Royalprint("helloworld", __name__, url_prefix="/helloworld") - - -@bp.route("/") -def helloworld_index(): - return "Hello world!" diff --git a/royalnet/web/blueprints/testing/__init__.py b/royalnet/web/blueprints/testing/__init__.py deleted file mode 100644 index 5f3fd3a5..00000000 --- a/royalnet/web/blueprints/testing/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -import flask as f -from ... import Royalprint -from ....database.tables import Royal - - -bp = Royalprint("testing", __name__, url_prefix="/testing", required_tables={Royal}) - - -@bp.route("/listroyals") -def testing_listroyals(): - from ...alchemyhandler import alchemy, alchemy_session - royals = alchemy_session.query(alchemy.Royal).all() - return f'
' diff --git a/royalnet/web/blueprints/tglogin/__init__.py b/royalnet/web/blueprints/tglogin/__init__.py index 2fde4679..280fc838 100644 --- a/royalnet/web/blueprints/tglogin/__init__.py +++ b/royalnet/web/blueprints/tglogin/__init__.py @@ -18,7 +18,7 @@ def tglogin_index(): @bp.route("/done") def tglogin_done(): - from ...alchemyhandler import alchemy, alchemy_session + alchemy, alchemy_session = f.current_app.config["ALCHEMY"], f.current_app.config["ALCHEMY_SESSION"] data_check_string = "" for field in sorted(list(f.request.args)): if field == "hash": diff --git a/royalnet/web/blueprints/wikiview/__init__.py b/royalnet/web/blueprints/wikiview/__init__.py index 436f308d..23790f0d 100644 --- a/royalnet/web/blueprints/wikiview/__init__.py +++ b/royalnet/web/blueprints/wikiview/__init__.py @@ -50,7 +50,7 @@ def prepare_page(page): @bp.route("/") def wikiview_index(): - from ...alchemyhandler import alchemy, alchemy_session + alchemy, alchemy_session = f.current_app.config["ALCHEMY"], f.current_app.config["ALCHEMY_SESSION"] pages = sorted(alchemy_session.query(alchemy.WikiPage).all(), key=lambda page: page.title) return f.render_template("wikiview_index.html", pages=pages) @@ -58,7 +58,7 @@ def wikiview_index(): @bp.route("/