-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1933 from NYPL-Simplified/TGR-35-circulation-mana…
…ger-dependabot-alerts TGR-35 Requirements Upgrades
- Loading branch information
Showing
15 changed files
with
125 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
""" | ||
https://github.com/dtheodor/flask-sqlalchemy-session is archived | ||
Implements fixes to make it work with modern Werkzeug | ||
https://github.com/dtheodor/flask-sqlalchemy-session/pull/17 | ||
https://github.com/dtheodor/flask-sqlalchemy-session/pull/15 | ||
""" | ||
|
||
from flask import current_app | ||
from sqlalchemy.orm import scoped_session | ||
from werkzeug.local import LocalProxy | ||
|
||
|
||
def _get_session(): | ||
app = current_app._get_current_object() | ||
if not hasattr(app, "scoped_session"): | ||
raise AttributeError( | ||
"{} has no 'scoped_session' attribute. You need to initialize it " | ||
"with a flask_scoped_session.".format(app) | ||
) | ||
return app.scoped_session | ||
|
||
|
||
current_session = LocalProxy(_get_session) | ||
"""Provides the current SQL Alchemy session within a request. | ||
Will raise an exception if no :data:`~flask.current_app` is available or it has | ||
not been initialized with a :class:`flask_scoped_session` | ||
""" | ||
|
||
|
||
class flask_scoped_session(scoped_session): | ||
"""A :class:`~sqlalchemy.orm.scoping.scoped_session` whose scope is set to | ||
the Flask application context. | ||
""" | ||
|
||
def __init__(self, session_factory, app=None): | ||
""" | ||
:param session_factory: A callable that returns a | ||
:class:`~sqlalchemy.orm.session.Session` | ||
:param app: a :class:`~flask.Flask` application | ||
""" | ||
try: | ||
from greenlet import getcurrent as scopefunc | ||
except ImportError: | ||
from threading import get_ident as scopefunc | ||
super().__init__(session_factory, scopefunc=scopefunc) | ||
if app is not None: | ||
self.init_app(app) | ||
|
||
def init_app(self, app): | ||
"""Setup scoped session creation and teardown for the passed ``app``. | ||
:param app: a :class:`~flask.Flask` application | ||
""" | ||
app.scoped_session = self | ||
|
||
@app.teardown_appcontext | ||
def remove_scoped_session(*args, **kwargs): | ||
app.scoped_session.remove() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.