[Mpuls-commits] r3381 - in base/trunk: . mpulsweb/lib
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Aug 11 17:03:43 CEST 2010
Author: bh
Date: 2010-08-11 17:03:41 +0200 (Wed, 11 Aug 2010)
New Revision: 3381
Added:
base/trunk/mpulsweb/lib/session.py
Modified:
base/trunk/ChangeLog
base/trunk/mpulsweb/lib/app_globals.py
base/trunk/mpulsweb/lib/base.py
base/trunk/mpulsweb/lib/helpers.py
base/trunk/mpulsweb/lib/navigation.py
base/trunk/mpulsweb/lib/security.py
Log:
* mpulsweb/lib/app_globals.py (session): StackedObjectProxy
instance holding the mpuls session object.
* mpulsweb/lib/base.py: Import session from app_globals instead of
using the one from pylons.
(render_mako.render_template): Use the mpuls session as the
session object.
(BaseController.__before__): Register the right application
specific mpuls session wrapper for the current request
* mpulsweb/lib/helpers.py, mpulsweb/lib/navigation.py,
mpulsweb/lib/security.py: Import session directly from app_globals
instead of from pylons. Importing from base.py would introduce
hard to resolve circular imports.
* mpulsweb/lib/session.py: New. MPuls specific wrapper for the
pylons session
Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog 2010-08-11 12:33:36 UTC (rev 3380)
+++ base/trunk/ChangeLog 2010-08-11 15:03:41 UTC (rev 3381)
@@ -1,5 +1,25 @@
2010-08-11 Bernhard Herzog <bh at intevation.de>
+ * mpulsweb/lib/session.py: New. MPuls specific wrapper for the
+ pylons session
+
+ * mpulsweb/lib/app_globals.py (session): StackedObjectProxy
+ instance holding the mpuls session object.
+
+ * mpulsweb/lib/base.py: Import session from app_globals instead of
+ using the one from pylons.
+ (render_mako.render_template): Use the mpuls session as the
+ session object.
+ (BaseController.__before__): Register the right application
+ specific mpuls session wrapper for the current request
+
+ * mpulsweb/lib/helpers.py, mpulsweb/lib/navigation.py,
+ mpulsweb/lib/security.py: Import session directly from app_globals
+ instead of from pylons. Importing from base.py would introduce
+ hard to resolve circular imports.
+
+2010-08-11 Bernhard Herzog <bh at intevation.de>
+
* mpulsweb/controllers/administration.py,
mpulsweb/controllers/auth.py, mpulsweb/controllers/case.py,
mpulsweb/controllers/casedocument.py,
Modified: base/trunk/mpulsweb/lib/app_globals.py
===================================================================
--- base/trunk/mpulsweb/lib/app_globals.py 2010-08-11 12:33:36 UTC (rev 3380)
+++ base/trunk/mpulsweb/lib/app_globals.py 2010-08-11 15:03:41 UTC (rev 3381)
@@ -28,6 +28,7 @@
import logging
from paste.reloader import watch_file
+from paste.registry import StackedObjectProxy
from pylons import config
@@ -43,6 +44,14 @@
log = logging.getLogger(__name__)
+# MPuls session object. Application specific wrapper around the pylons
+# session object. The actual functionality is defined in
+# mpulsweb/lib/session.py. It's set on a per-request basis in
+# mpulsweb/lib/base.py. It's located here in app_globals.py to avoid
+# excessive problems with circular imports.
+session = StackedObjectProxy()
+
+
class Globals(object):
"""Globals acts as a container for objects available throughout the
Modified: base/trunk/mpulsweb/lib/base.py
===================================================================
--- base/trunk/mpulsweb/lib/base.py 2010-08-11 12:33:36 UTC (rev 3380)
+++ base/trunk/mpulsweb/lib/base.py 2010-08-11 15:03:41 UTC (rev 3381)
@@ -37,7 +37,7 @@
from routes import url_for
-from pylons import c, config, g, request, response, session
+from pylons import c, config, g, request, response
from pylons.controllers import WSGIController
from pylons.controllers.util import redirect_to, redirect
#from mpulsweb.lib.translation import _
@@ -46,11 +46,12 @@
from webhelpers.html import literal
+from mpulsweb.config.importer import import_overridable_module
import mpulsweb.lib.db as db
from mpulsweb.lib.translation import set_lang, _
from mpulsweb.lib.timelog import timeLog
from mpulsweb.lib.navigation import get_navigation
-
+from mpulsweb.lib.app_globals import session
import mpulsweb.lib.helpers as h
from mpulsweb.lib.security import getDbName, userIdentity, get_db_parameters
@@ -62,13 +63,13 @@
"request", "response", "session"]
-
COOKIE_NOT_FOUND = ("Cookie konnte nicht gefunden werden."
" Haben Sie Cookies in Ihrem Browser aktiviert?")
IDENTITY_CHANGED = "Ihre Identitaet hat sich geaendert."
log = logging.getLogger(__name__)
+
# Added own render_mako function which addes custom translation functions
def render_mako(template_name, extra_vars=None, cache_key=None,
cache_type=None, cache_expire=None):
@@ -88,6 +89,7 @@
# Thirs overwritw '_'
globs.update({'_': _})
+ globs["session"] = session
# Grab a template reference
template = globs['app_globals'].mako_lookup.get_template(template_name)
@@ -125,7 +127,11 @@
session.save()
return case
- def __before__(self):
+ def __before__(self, environ):
+ mpuls_session_module = import_overridable_module("lib.session")
+ environ['paste.registry'].register(session,
+ mpuls_session_module.MPulsSession())
+
try:
storedHash = session['AUTH']
try:
Modified: base/trunk/mpulsweb/lib/helpers.py
===================================================================
--- base/trunk/mpulsweb/lib/helpers.py 2010-08-11 12:33:36 UTC (rev 3380)
+++ base/trunk/mpulsweb/lib/helpers.py 2010-08-11 15:03:41 UTC (rev 3381)
@@ -36,8 +36,7 @@
from string import printable
from xml.sax.saxutils import quoteattr
-# we still import session from pylons here because of circular imports
-from pylons import c, cache, config, g, request, response, session, url
+from pylons import c, cache, config, g, request, response, url
from mpulsweb.lib.translation import _
# Use url_for from prior versions
@@ -52,7 +51,11 @@
from mpulsweb.lib.helper.filters import shorten, nl_to_br, NA
+# normally we would import session from mpulsweb.lib.base, but to avoid
+# circular imports we import it from app_globals.
+from mpulsweb.lib.app_globals import session
+
PRINTABLE = frozenset(printable)
log = logging.getLogger(__name__)
Modified: base/trunk/mpulsweb/lib/navigation.py
===================================================================
--- base/trunk/mpulsweb/lib/navigation.py 2010-08-11 12:33:36 UTC (rev 3380)
+++ base/trunk/mpulsweb/lib/navigation.py 2010-08-11 15:03:41 UTC (rev 3381)
@@ -41,9 +41,12 @@
from mpulsweb.lib.translation import _
from mpulsweb.lib.db import PostgresDBInterface
import mpulsweb.lib.helpers
-from mpulsweb.lib.base import session
+# normally we would import session from mpulsweb.lib.base, but to avoid
+# circular imports we import it from app_globals.
+from mpulsweb.lib.app_globals import session
+
log = logging.getLogger(__name__)
Modified: base/trunk/mpulsweb/lib/security.py
===================================================================
--- base/trunk/mpulsweb/lib/security.py 2010-08-11 12:33:36 UTC (rev 3380)
+++ base/trunk/mpulsweb/lib/security.py 2010-08-11 15:03:41 UTC (rev 3381)
@@ -43,12 +43,16 @@
from decorator import decorator
from webob.exc import HTTPUnauthorized
-# we still import session from pylons here because of circular imports
-from pylons import request, session, config, g
+from pylons import request, config, g
+
from mpulsweb.lib.db import DB, db, enter, leave
+# normally we would import session from mpulsweb.lib.base, but to avoid
+# circular imports we import it from app_globals.
+from mpulsweb.lib.app_globals import session
+
log = logging.getLogger(__name__)
# maps new FKZs to old
Added: base/trunk/mpulsweb/lib/session.py
===================================================================
--- base/trunk/mpulsweb/lib/session.py 2010-08-11 12:33:36 UTC (rev 3380)
+++ base/trunk/mpulsweb/lib/session.py 2010-08-11 15:03:41 UTC (rev 3381)
@@ -0,0 +1,58 @@
+"""MPuls extensions for session data"""
+
+from pylons import session
+
+
+class MPulsSession:
+
+ """Extends the pylons session by prefixing all keys with an
+ application specific string.
+
+ This way, when multiple MPuls applications are run in the same
+ server do no interfere with each other, even when they share the
+ session storage. Derived classes may override methods, especially
+ translate_key to let application share some session entries.
+ """
+
+ # The prefix to add to the keys.
+ key_prefix = "mpuls"
+
+ def __init__(self):
+ pass
+
+ def translate_key(self, key):
+ """Return the actual session key for the key.
+ All methods that handle keys, use this method to translate the
+ keys given to the function into the key to be used when
+ accessing the pylons session object.
+ In this default implementation the actual session key is key
+ prefixed with self.key_prefix and a period ('.'). Derived
+ classes should override this method if they want to treat some
+ keys differently.
+ """
+ return self.key_prefix + "." + key
+
+ def __getitem__(self, key):
+ return session[self.translate_key(key)]
+
+ def __setitem__(self, key, value):
+ session[self.translate_key(key)] = value
+
+ def __delitem__(self, key, value):
+ del session[self.translate_key(key)]
+
+ def get(self, key, default=None):
+ return session.get(self.translate_key(key), default)
+
+ def has_key(self, key):
+ return session.has_key(self.translate_key(key))
+
+ def save(self):
+ session.save()
+
+ def delete(self):
+ session.delete()
+
+ def invalidate(self):
+ session.invalidate()
+
Property changes on: base/trunk/mpulsweb/lib/session.py
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
More information about the Mpuls-commits
mailing list