summaryrefslogtreecommitdiff
path: root/addons/web/controllers
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2013-03-13 10:49:09 +0100
committerXavier Morel <xmo@openerp.com>2013-03-13 10:49:09 +0100
commit94c2c42be6fc0bdf55421b3fe4c1d4c7db1f4bed (patch)
tree395948faff8d6874a5094dc632b238a8eff32b4e /addons/web/controllers
parenta67b8721848083a9336317139e508c338d925f73 (diff)
parentf79f6a5a25a0708e662f2deed4a54c704c6872b5 (diff)
[MERGE] from 7.0
bzr revid: xmo@openerp.com-20130313094909-u21ee88l2lak9p2x
Diffstat (limited to 'addons/web/controllers')
-rw-r--r--addons/web/controllers/main.py65
1 files changed, 52 insertions, 13 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py
index 87af7474daf..8f1855f205d 100644
--- a/addons/web/controllers/main.py
+++ b/addons/web/controllers/main.py
@@ -15,6 +15,8 @@ import simplejson
import time
import urllib
import urllib2
+import urlparse
+import xmlrpclib
import zlib
from xml.etree import ElementTree
from cStringIO import StringIO
@@ -91,16 +93,50 @@ def db_list(req):
dbs = [i for i in dbs if re.match(r, i)]
return dbs
-def db_monodb(req):
- # if only one db exists, return it else return False
+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)
- if len(dbs) == 1:
- return dbs[0]
except Exception:
# ignore access denied
- pass
- return False
+ dbs = []
+
+ # 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
+
+ # 3 use the first db
+ if dbs and not db:
+ 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, redirect)
+
+def db_monodb(req):
+ # if only one db exists, return it else return False
+ return db_monodb_redirect(req)[0]
+
+def redirect_with_hash(req, url, code=303):
+ if req.httprequest.user_agent.browser == 'msie':
+ try:
+ version = float(req.httprequest.user_agent.version)
+ if version < 10:
+ return "<html><head><script>window.location = '%s#' + location.hash;</script></head></html>" % url
+ except Exception:
+ pass
+ return werkzeug.utils.redirect(url, code)
def module_topological_sort(modules):
""" Return a list of module names sorted so that their dependencies of the
@@ -291,6 +327,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:
@@ -299,12 +339,7 @@ def manifest_list(req, extension, mods=None, db=None):
path += '?' + urllib.urlencode({'db': db})
return [path]
files = manifest_glob(req, extension, addons=mods, db=db)
- i_am_diabetic = req.httprequest.environ["QUERY_STRING"].count("no_sugar") >= 1 or \
- req.httprequest.environ.get('HTTP_REFERER', '').count("no_sugar") >= 1
- if i_am_diabetic:
- return [wp for _fp, wp in files]
- else:
- return ['%s?debug=%s' % (wp, os.path.getmtime(fp)) for fp, wp in files]
+ return [wp for _fp, wp in files]
def get_last_modified(files):
""" Returns the modification time of the most recently modified
@@ -534,6 +569,10 @@ class Home(openerpweb.Controller):
@openerpweb.httprequest
def index(self, req, s_action=None, db=None, **kw):
+ db, redir = db_monodb_redirect(req)
+ if redir:
+ return redirect_with_hash(req, redir)
+
js = "\n ".join('<script type="text/javascript" src="%s"></script>' % i for i in manifest_list(req, 'js', db=db))
css = "\n ".join('<link rel="stylesheet" href="%s">' % i for i in manifest_list(req, 'css', db=db))
@@ -869,7 +908,7 @@ class Session(openerpweb.Controller):
"""
saved_actions = req.httpsession.get('saved_actions')
if not saved_actions:
- saved_actions = {"next":0, "actions":{}}
+ saved_actions = {"next":1, "actions":{}}
req.httpsession['saved_actions'] = saved_actions
# we don't allow more than 10 stored actions
if len(saved_actions["actions"]) >= 10: