Put db_monodb() method in http.py
bzr revid: nicolas.vanhoren@openerp.com-20130621124143-pe5hgwj81j2degg6
This commit is contained in:
parent
93979c30b8
commit
52d1b26b2f
|
@ -86,14 +86,7 @@ def rjsmin(script):
|
|||
).strip()
|
||||
return result
|
||||
|
||||
def db_list():
|
||||
proxy = request.session.proxy("db")
|
||||
dbs = proxy.list()
|
||||
h = request.httprequest.environ['HTTP_HOST'].split(':')[0]
|
||||
d = h.split('.')[0]
|
||||
r = openerp.tools.config['dbfilter'].replace('%h', h).replace('%d', d)
|
||||
dbs = [i for i in dbs if re.match(r, i)]
|
||||
return dbs
|
||||
db_list = http.db_list
|
||||
|
||||
def db_monodb_redirect():
|
||||
db = db_monodb()
|
||||
|
@ -115,29 +108,7 @@ def db_monodb_redirect():
|
|||
redirect = request.httprequest.path + '?' + urllib.urlencode(query)
|
||||
return (db, redirect)
|
||||
|
||||
def db_monodb():
|
||||
db = False
|
||||
|
||||
# 1 try the db in the url
|
||||
db_url = request.params.get('db')
|
||||
if db_url:
|
||||
return db_url
|
||||
|
||||
try:
|
||||
dbs = db_list()
|
||||
except Exception:
|
||||
# ignore access denied
|
||||
dbs = []
|
||||
|
||||
# 2 use the database from the cookie if it's listable and still listed
|
||||
cookie_db = request.httprequest.cookies.get('last_used_database')
|
||||
if cookie_db in dbs:
|
||||
db = cookie_db
|
||||
|
||||
# 3 use the first db
|
||||
if dbs and not db:
|
||||
db = dbs[0]
|
||||
return db
|
||||
db_monodb = http.db_monodb
|
||||
|
||||
def redirect_with_hash(url, code=303):
|
||||
if request.httprequest.user_agent.browser == 'msie':
|
||||
|
|
|
@ -20,6 +20,7 @@ import traceback
|
|||
import urlparse
|
||||
import uuid
|
||||
import errno
|
||||
import re
|
||||
|
||||
import babel.core
|
||||
import simplejson
|
||||
|
@ -121,7 +122,7 @@ class WebRequest(object):
|
|||
self.httpsession[self.session_id] = self.session
|
||||
|
||||
with set_request(self):
|
||||
self.db = (self.session._db or openerp.addons.web.controllers.main.db_monodb()).lower()
|
||||
self.db = self.session._db or db_monodb()
|
||||
|
||||
# TODO: remove this
|
||||
# set db/uid trackers - they're cleaned up at the WSGI
|
||||
|
@ -153,7 +154,7 @@ class WebRequest(object):
|
|||
self.db = None
|
||||
self.uid = None
|
||||
elif self.auth_method == "db":
|
||||
self.db = (self.session._db or openerp.addons.web.controllers.main.db_monodb()).lower()
|
||||
self.db = self.session._db or db_monodb()
|
||||
if not self.db:
|
||||
raise SessionExpiredException("No valid database for request %s" % self.httprequest)
|
||||
self.uid = None
|
||||
|
@ -1031,7 +1032,7 @@ class Root(object):
|
|||
members = inspect.getmembers(o)
|
||||
for mk, mv in members:
|
||||
if inspect.ismethod(mv) and getattr(mv, 'exposed', False) and \
|
||||
nodb_only == (getattr(mv, "user", None) == "none"):
|
||||
nodb_only == (getattr(mv, "auth", None) == "none"):
|
||||
function = (o.get_wrapped_method(mk), mv)
|
||||
for url in mv.routes:
|
||||
if getattr(mv, "combine", False):
|
||||
|
@ -1091,6 +1092,39 @@ class Root(object):
|
|||
request.auth_method = getattr(original, "auth", "user")
|
||||
request.func_request_type = original.exposed
|
||||
|
||||
def db_list():
|
||||
proxy = request.session.proxy("db")
|
||||
dbs = proxy.list()
|
||||
h = request.httprequest.environ['HTTP_HOST'].split(':')[0]
|
||||
d = h.split('.')[0]
|
||||
r = openerp.tools.config['dbfilter'].replace('%h', h).replace('%d', d)
|
||||
dbs = [i for i in dbs if re.match(r, i)]
|
||||
return dbs
|
||||
|
||||
def db_monodb():
|
||||
db = None
|
||||
|
||||
# 1 try the db in the url
|
||||
db_url = request.params.get('db')
|
||||
if db_url:
|
||||
return db_url
|
||||
|
||||
try:
|
||||
dbs = db_list()
|
||||
except Exception:
|
||||
# ignore access denied
|
||||
dbs = []
|
||||
|
||||
# 2 use the database from the cookie if it's listable and still listed
|
||||
cookie_db = request.httprequest.cookies.get('last_used_database')
|
||||
if cookie_db in dbs:
|
||||
db = cookie_db
|
||||
|
||||
# 3 use the first db
|
||||
if dbs and not db:
|
||||
db = dbs[0]
|
||||
return db.lower() if db else db
|
||||
|
||||
def wsgi_postload():
|
||||
openerp.wsgi.register_wsgi_handler(Root())
|
||||
|
||||
|
|
Loading…
Reference in New Issue