db_monodb better version and naming
bzr revid: al@openerp.com-20130306005755-bgyl65f03st6mn6x
This commit is contained in:
parent
b5b625932a
commit
88e0e2933c
|
@ -93,28 +93,40 @@ def db_list(req):
|
|||
dbs = [i for i in dbs if re.match(r, i)]
|
||||
return dbs
|
||||
|
||||
def db_monodb_list(req):
|
||||
def db_monodb_redirect(req):
|
||||
db = False
|
||||
redirect = False
|
||||
|
||||
# 1 try the db in the url
|
||||
db_url = req.params.get('db')
|
||||
if db_url:
|
||||
return (db_url, False)
|
||||
|
||||
try:
|
||||
dbs = db_list(req)
|
||||
except xmlrpclib.Fault:
|
||||
# ignore access denied
|
||||
dbs = []
|
||||
|
||||
db = db_url = req.params.get('db') or False
|
||||
if not db:
|
||||
first_db = dbs[0] if dbs else False
|
||||
db = req.httprequest.cookies.get('last_used_database') or first_db
|
||||
# 2 use the database from the cookie if it's listable and still listed
|
||||
cookie_db = req.httprequest.cookies.get('last_used_database')
|
||||
if cookie_db in dbs:
|
||||
db = cookie_db
|
||||
|
||||
redirect = False
|
||||
if db and db_url != db and len(dbs) > 1:
|
||||
# 3 use the first db
|
||||
if dbs:
|
||||
db = dbs[0]
|
||||
|
||||
# redirect to the chosen db if multiple are available
|
||||
if db and len(dbs) > 1:
|
||||
query = dict(urlparse.parse_qsl(req.httprequest.query_string, keep_blank_values=True))
|
||||
query.update({ 'db': db })
|
||||
redirect = req.httprequest.path + '?' + urllib.urlencode(query)
|
||||
return (db, dbs, redirect)
|
||||
return (db, redirect)
|
||||
|
||||
def db_monodb(req):
|
||||
# if only one db exists, return it else return False
|
||||
return db_monodb_list(req)[0]
|
||||
return db_monodb_redirect(req)[0]
|
||||
|
||||
def module_topological_sort(modules):
|
||||
""" Return a list of module names sorted so that their dependencies of the
|
||||
|
@ -305,6 +317,10 @@ def manifest_glob(req, extension, addons=None, db=None):
|
|||
return r
|
||||
|
||||
def manifest_list(req, extension, mods=None, db=None):
|
||||
""" list ressources to load specifying either:
|
||||
mods: a comma separated string listing modules
|
||||
db: a database name (return all installed modules in that database)
|
||||
"""
|
||||
if not req.debug:
|
||||
path = '/web/webclient/' + extension
|
||||
if mods is not None:
|
||||
|
@ -548,7 +564,7 @@ class Home(openerpweb.Controller):
|
|||
|
||||
@openerpweb.httprequest
|
||||
def index(self, req, s_action=None, db=None, **kw):
|
||||
db, dbs, redir = db_monodb_list(req)
|
||||
db, redir = db_monodb_redirect(req)
|
||||
if redir:
|
||||
return werkzeug.utils.redirect(redir, 303)
|
||||
|
||||
|
|
Loading…
Reference in New Issue