from mediagoblin.tools.crypto import setup_crypto
from mediagoblin.auth.tools import check_auth_enabled, no_auth_logout
+from mediagoblin.tools.transition import DISABLE_GLOBALS
+
_log = logging.getLogger(__name__)
# certain properties need to be accessed globally eg from
# validators, etc, which might not access to the request
# object.
+ #
+ # Note, we are trying to transition this out;
+ # run with environment variable DISABLE_GLOBALS=true
+ # to work on it
#######################################################
- setup_globals(app=self)
+ if not DISABLE_GLOBALS:
+ setup_globals(app=self)
# Workbench *currently* only used by celery, so this only
# matters in always eager mode :)
# --------------
# Is a context provided?
- if ctx is not None:
- # Do special things if this is a request
- if isinstance(ctx, Request):
- ctx = self._request_only_gen_context(ctx)
-
- else:
+ if ctx is None:
ctx = Context()
# Attach utilities
ctx.db = self.db
ctx.staticdirect = self.staticdirector
+ # Do special things if this is a request
+ # --------------------------------------
+ if isinstance(ctx, Request):
+ ctx = self._request_only_gen_context(ctx)
+
return ctx
def _request_only_gen_context(self, request):
from sqlalchemy.orm import scoped_session, sessionmaker, object_session
from sqlalchemy import inspect
-Session = scoped_session(sessionmaker())
+from mediagoblin.tools.transition import DISABLE_GLOBALS
+if not DISABLE_GLOBALS:
+ Session = scoped_session(sessionmaker())
class GMGTableBase(object):
def _session(self):
return inspect(self).session
- query = Session.query_property()
+ if not DISABLE_GLOBALS:
+ query = Session.query_property()
def get(self, key):
return getattr(self, key)
return getattr(self, key)
def save(self, commit=True):
- sess = object_session(self)
- if sess is None:
+ sess = self._session
+ if sess is None and not DISABLE_GLOBALS:
sess = Session()
+ assert sess is not None, "Can't save, %r has a detached session" % self
sess.add(self)
if commit:
sess.commit()
def delete(self, commit=True):
"""Delete the object and commit the change immediately by default"""
- sess = object_session(self)
+ sess = self._session
assert sess is not None, "Not going to delete detached %r" % self
sess.delete(self)
if commit:
--- /dev/null
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+import os
+
+# one global to disable them all
+DISABLE_GLOBALS = os.environ.get("DISABLE_GLOBALS", "false").lower() == "true"