[ADD] http#ensure_db()
A helper that allows to force a db in the controller context otherwise redirect to database selector Used for /web, /web/login and auth_* modules bzr revid: fme@openerp.com-20140128211550-vmhy5nu0qbi33qh5
This commit is contained in:
parent
38e651cbd2
commit
cfaadc0433
|
@ -72,6 +72,28 @@ def redirect_with_hash(url, code=303):
|
||||||
return werkzeug.utils.redirect(url, code)
|
return werkzeug.utils.redirect(url, code)
|
||||||
return "<html><head><script>window.location = '%s' + location.hash;</script></head></html>" % url
|
return "<html><head><script>window.location = '%s' + location.hash;</script></head></html>" % url
|
||||||
|
|
||||||
|
def ensure_db(with_registry=False, redirect='/web/database/selector'):
|
||||||
|
db = request.params.get('db')
|
||||||
|
# if db not provided, use the session one
|
||||||
|
if not db:
|
||||||
|
db = request.session.db
|
||||||
|
|
||||||
|
# if no database provided and no database in session, use monodb
|
||||||
|
if not db:
|
||||||
|
db = db_monodb(request.httprequest)
|
||||||
|
|
||||||
|
# if no db can be found til here, send to the database selector
|
||||||
|
# the database selector will redirect to database manager if needed
|
||||||
|
if not db:
|
||||||
|
werkzeug.exceptions.abort(werkzeug.utils.redirect(redirect, 303))
|
||||||
|
|
||||||
|
# always switch the session to the computed db
|
||||||
|
if db != request.session.db:
|
||||||
|
request.session.logout()
|
||||||
|
request.session.db = db
|
||||||
|
|
||||||
|
if with_registry:
|
||||||
|
request.disable_db = False
|
||||||
|
|
||||||
class WebRequest(object):
|
class WebRequest(object):
|
||||||
""" Parent class for all OpenERP Web request types, mostly deals with
|
""" Parent class for all OpenERP Web request types, mostly deals with
|
||||||
|
@ -667,9 +689,10 @@ class OpenERPSession(werkzeug.contrib.sessions.Session):
|
||||||
raise SessionExpiredException("Session expired")
|
raise SessionExpiredException("Session expired")
|
||||||
security.check(self.db, self.uid, self.password)
|
security.check(self.db, self.uid, self.password)
|
||||||
|
|
||||||
def logout(self):
|
def logout(self, keep_db=False):
|
||||||
for k in self.keys():
|
for k in self.keys():
|
||||||
del self[k]
|
if not (keep_db and k == 'db'):
|
||||||
|
del self[k]
|
||||||
self._default_values()
|
self._default_values()
|
||||||
|
|
||||||
def _default_values(self):
|
def _default_values(self):
|
||||||
|
|
Loading…
Reference in New Issue