Set up request.db / app.db(_manager) depending on DISABLE_GLOBALS
This commit is contained in:
parent
2026752120
commit
c060353e35
@ -106,6 +106,9 @@ class MediaGoblinApp(object):
|
|||||||
setup_plugins()
|
setup_plugins()
|
||||||
|
|
||||||
# Set up the database
|
# Set up the database
|
||||||
|
if DISABLE_GLOBALS:
|
||||||
|
self.db_manager = setup_database(app_config['run_migrations'])
|
||||||
|
else:
|
||||||
self.db = setup_database(app_config['run_migrations'])
|
self.db = setup_database(app_config['run_migrations'])
|
||||||
|
|
||||||
# Quit app if need to run dbupdate
|
# Quit app if need to run dbupdate
|
||||||
@ -191,7 +194,9 @@ class MediaGoblinApp(object):
|
|||||||
# Also attach a few utilities from request.app for convenience?
|
# Also attach a few utilities from request.app for convenience?
|
||||||
ctx.app = self
|
ctx.app = self
|
||||||
|
|
||||||
|
if not DISABLE_GLOBALS:
|
||||||
ctx.db = self.db
|
ctx.db = self.db
|
||||||
|
|
||||||
ctx.staticdirect = self.staticdirector
|
ctx.staticdirect = self.staticdirector
|
||||||
|
|
||||||
# Do special things if this is a request
|
# Do special things if this is a request
|
||||||
@ -300,6 +305,10 @@ class MediaGoblinApp(object):
|
|||||||
|
|
||||||
# get the Http response from the controller
|
# get the Http response from the controller
|
||||||
try:
|
try:
|
||||||
|
if DISABLE_GLOBALS:
|
||||||
|
with self.db_manager.session_scope() as request.db:
|
||||||
|
response = controller(request)
|
||||||
|
else:
|
||||||
response = controller(request)
|
response = controller(request)
|
||||||
except HTTPException as e:
|
except HTTPException as e:
|
||||||
response = render_http_exception(
|
response = render_http_exception(
|
||||||
@ -326,6 +335,7 @@ class MediaGoblinApp(object):
|
|||||||
try:
|
try:
|
||||||
return self.call_backend(environ, start_response)
|
return self.call_backend(environ, start_response)
|
||||||
finally:
|
finally:
|
||||||
|
if not DISABLE_GLOBALS:
|
||||||
# Reset the sql session, so that the next request
|
# Reset the sql session, so that the next request
|
||||||
# gets a fresh session
|
# gets a fresh session
|
||||||
self.db.reset_after_request()
|
self.db.reset_after_request()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user