Merge lp:~openerp-dev/openerp-web/trunk-webdb-niv into lp:openerp-web

Proposed by Nicolas Vanhoren (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openerp-web/trunk-webdb-niv
Merge into: lp:openerp-web
Diff against target: 64 lines (+26/-11)
1 file modified
addons/web/controllers/main.py (+26/-11)
To merge this branch: bzr merge lp:~openerp-dev/openerp-web/trunk-webdb-niv
Reviewer Review Type Date Requested Status
Xavier (Open ERP) Pending
Review via email: mp+194149@code.launchpad.net

Description of the change

I let you merge it if you need it.

To post a comment you must log in.

Unmerged revisions

3876. By Nicolas Vanhoren (OpenERP)

Fixed problem with not setting correctly the db in the session and rewrite a part of the web_admin method.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/web/controllers/main.py'
2--- addons/web/controllers/main.py 2013-11-05 15:21:38 +0000
3+++ addons/web/controllers/main.py 2013-11-06 14:35:55 +0000
4@@ -537,12 +537,11 @@
5 def web_client(self, s_action=None, db=None, debug=False, **kw):
6 debug = debug != False
7
8+ # if a db is explicitely specified, we check it's a valid database (even if we can't list the dbs),
9+ # if it's not we ignore that parameter
10 lst = http.db_list(True)
11 if db not in lst:
12 db = None
13- guessed_db = http.db_monodb(request.httprequest)
14- if guessed_db is None and len(lst) > 0:
15- guessed_db = lst[0]
16
17 def redirect(db):
18 query = dict(urlparse.parse_qsl(request.httprequest.query_string, keep_blank_values=True))
19@@ -550,21 +549,37 @@
20 redirect = request.httprequest.path + '?' + urllib.urlencode(query)
21 return redirect_with_hash(redirect)
22
23- if db is None and guessed_db is not None:
24- return redirect(guessed_db)
25+ # it we don't have an explicit db, we try to guess the default database. If the --db-filters could
26+ # not match a single db, we take a look at all the valid ones and take the first one if it exists.
27+ if db is None:
28+ guessed_db = request.session.db
29+ if guessed_db is None:
30+ # TODO: check there is no exceptions
31+ try:
32+ nlst = http.db_list(False)
33+ except openerp.exceptions.AccessDenied, e:
34+ nlst = []
35+ if len(nlst) > 0:
36+ guessed_db = nlst[0]
37+ # if there is no specified db and we were able to guess a db we redirect to a url that explicitely
38+ # target that db
39+ if guessed_db is not None:
40+ return redirect(guessed_db)
41
42- if db is not None and db != guessed_db:
43+ # if the db differs from the one stored in the session, we reinit the session
44+ if db != request.session.db:
45 request.session.logout()
46 request.session.db = db
47- guessed_db = db
48-
49- js = "\n ".join('<script type="text/javascript" src="%s"></script>' % i for i in manifest_list('js', db=guessed_db, debug=debug))
50- css = "\n ".join('<link rel="stylesheet" href="%s">' % i for i in manifest_list('css', db=guessed_db, debug=debug))
51+
52+ # at this point, it's still possible that db is None, which is the case when there are no dbs at all
53+
54+ js = "\n ".join('<script type="text/javascript" src="%s"></script>' % i for i in manifest_list('js', db=db, debug=debug))
55+ css = "\n ".join('<link rel="stylesheet" href="%s">' % i for i in manifest_list('css', db=db, debug=debug))
56
57 r = html_template % {
58 'js': js,
59 'css': css,
60- 'modules': simplejson.dumps(module_boot(db=guessed_db)),
61+ 'modules': simplejson.dumps(module_boot(db=db)),
62 'init': 'var wc = new s.web.WebClient();wc.appendTo($(document.body));'
63 }
64 return request.make_response(r, {'Cache-Control': 'no-cache', 'Content-Type': 'text/html; charset=utf-8'})